public class Draw extends JPanel{
public Draw(){
super();
setLayout(null);
JLabel label=new JLabel("label");
label.setToolTipText("display");
label.setBounds(400,100,400,20);
add(label);
}
public paintComponent(Graphics g){ g.drawLine(30,30,40,20);
}} 在main()中:
JFrame showFrame=new JFrame("");
JScrollPane scrollPane=new JScrollPane();
showFrame.getContentPane().add(scrollPane);
Draw draw=new Draw();
scrollPane.setViewportView(draw);
showFrame.setBounds(200,200,200,30);//该窗体的宽度小于draw中label的宽度
showFrame.show();运行时出现2个问题:1 不显示滑动条;2 鼠标放置到label之后显示浮动的“diaplay”,鼠标移走后依旧显示。
求解决方案。
public Draw(){
super();
setLayout(null);
JLabel label=new JLabel("label");
label.setToolTipText("display");
label.setBounds(400,100,400,20);
add(label);
}
public paintComponent(Graphics g){ g.drawLine(30,30,40,20);
}} 在main()中:
JFrame showFrame=new JFrame("");
JScrollPane scrollPane=new JScrollPane();
showFrame.getContentPane().add(scrollPane);
Draw draw=new Draw();
scrollPane.setViewportView(draw);
showFrame.setBounds(200,200,200,30);//该窗体的宽度小于draw中label的宽度
showFrame.show();运行时出现2个问题:1 不显示滑动条;2 鼠标放置到label之后显示浮动的“diaplay”,鼠标移走后依旧显示。
求解决方案。
解决方案 »
- 弱弱的问一下,java api中已实现的排序方法比如快速排序在那些类中
- java 解压ZIP时ZIP内多个文件的内容解压到一个文件中了。
- private属性
- 怎样把jre压缩到5m以下??
- 求::《深入学习:Java多线程编程 》
- 大家对SWING熟悉吗
- 我用JET把我的.class弄成了.exe,在我的机器上可以运行,但环在别的机器上就不行,说是找不到XKRN25013.DLL,则么回事啊?
- 书上的java socket例子太简单,那位能提供复杂点的java server and client应用的代码呀
- 有没有人知道如何将weblogic挂到iisserver上,急!
- 关于TCP/IP下字节流传输的问题
- 如何在JPanel上插入背景图片.谢谢帮忙啦!
- 请教泛型题~
super.paintComponent(g); //******//
g.drawLine(30,30,40,20);
}
JFrame showFrame=new JFrame("");
JScrollPane scrollPane=new JScrollPane();
showFrame.getContentPane().add(scrollPane);
Draw draw=new Draw();
draw.setPreferredSize(new Dimension(900, 200)); //*****//
scrollPane.setViewportView(draw);
showFrame.setBounds(200,200,200,30);//该窗体的宽度小于draw中label的宽度
showFrame.show();
TooltipText可以显示了,但是滑动条没显示出来。我将Draw类构造函数中设置布局为setLayout(null),否则添加的标签无法定位。是不是因为布局管理器的原因而导致滑动条出不来?
public class Draw extends JPanel{
XYLayout xYLayout = new XYLayout();
public Draw(){
super();
setLayout(null);-->setLayout(xYLayout);
JLabel label=new JLabel("label");
label.setToolTipText("display");
label.setBounds(400,100,400,20);//删除
add(label);-->add(label,new XYConstraints(400,100,400,20))
}
public paintComponent(Graphics g){ g.drawLine(30,30,40,20);
}}
XYLayout是Jbuilder中特有的布局方式,大家以后在定位时可以考虑使用该布局
paintComponent需要调用super.paintComponent
/**
* @param args
*/
public static void main(String[] args)
{
JFrame showFrame = new JFrame("Draw"); JScrollPane scrollPane = new JScrollPane();
Draw draw = new Draw();
draw.setPreferredSize(new Dimension(500, 200));
scrollPane.setViewportView(draw);
showFrame.getContentPane().add(scrollPane); showFrame.setBounds(200, 200, 200, 100);
showFrame.setVisible(true);
} public Draw()
{
super(null);
JLabel label = new JLabel("label");
label.setToolTipText("display");
label.setBounds(400, 100, 400, 20);
add(label);
} @Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawLine(30, 30, 40, 20);
}