java 中JPanel 使用JScrollPane,(JScrollPane中还有一个JPanel),出问题了,请高手帮忙解决下
代码如下importjava.awt.Color;importjava.awt.Container;importjava.awt.Dimension;importjava...
代码如下
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class look extends JFrame
{
ImageIcon icon = new ImageIcon("D:/images/pro/jp.png");
look()
{
setDefaultCloseOperation(2);
Container con=this.getContentPane();
JPanel jp1= new JPanel()
{
protected void paintComponent(Graphics g)
{
g.drawImage(icon.getImage(), 0, 0, this);
super.paintComponents(g);
}
};
JPanel jp2
=new JPanel();
JScrollPane jsp=new JScrollPane(jp2);
setSize(300,200);
setVisible(true);
jp2.setBackground(Color.red);
jp2.setPreferredSize(new Dimension(200, 100));
jsp.setLocation(00, 100);
jsp.setSize(200, 50);
jp1.setLocation(0, 0);
jp1.setLayout(null);
jp1.setSize(getSize().width,getSize().height);
con.setLayout(null);
con.add(jp1);
jp1.add(jsp);
}
public static void main(String[] args)
{
// TODO Auto-generated method stub
new look();
}
}
运行后,最上面有一块红色(不应该有的),这块红色是jp2的背景色,是设置在JScrollPane里的,为什么多出来了呢? 展开
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class look extends JFrame
{
ImageIcon icon = new ImageIcon("D:/images/pro/jp.png");
look()
{
setDefaultCloseOperation(2);
Container con=this.getContentPane();
JPanel jp1= new JPanel()
{
protected void paintComponent(Graphics g)
{
g.drawImage(icon.getImage(), 0, 0, this);
super.paintComponents(g);
}
};
JPanel jp2
=new JPanel();
JScrollPane jsp=new JScrollPane(jp2);
setSize(300,200);
setVisible(true);
jp2.setBackground(Color.red);
jp2.setPreferredSize(new Dimension(200, 100));
jsp.setLocation(00, 100);
jsp.setSize(200, 50);
jp1.setLocation(0, 0);
jp1.setLayout(null);
jp1.setSize(getSize().width,getSize().height);
con.setLayout(null);
con.add(jp1);
jp1.add(jsp);
}
public static void main(String[] args)
{
// TODO Auto-generated method stub
new look();
}
}
运行后,最上面有一块红色(不应该有的),这块红色是jp2的背景色,是设置在JScrollPane里的,为什么多出来了呢? 展开
2个回答
TableDI
2024-07-18 广告
2024-07-18 广告
VLOOKUP是Excel中用于垂直查找的函数,其基本用法包括四个参数:1. 查找值:即在数据表首列中需要搜索的值。2. 数据表:包含查找值的单元格区域或数组。3. 返回值所在列数:指定返回查询区域中第几列的值。4. 查找方式:选择精确匹配...
点击进入详情页
本回答由TableDI提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询