java吧 关注:1,258,354贴子:12,751,797
  • 0回复贴,共1

java 滚动条问题,大神帮帮忙啊,急,谢谢!

只看楼主收藏回复

public class Test1 extends JFrame {
public Test1(){
this.setTitle("信用卡办理");
this.setSize(750, 450);
this.setResizable(false);
this.setLocation(350,100);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
/ /获取屏幕的宽度和高度,Dimension对象封装了宽度和高度的对象
Dimension dsion=
Toolkit.getDefaultToolkit().getScreenSize();
int w=dsion.width;//获取宽度
int h=dsion.height;//获取高度
//实例化面板对象
p1 = new JPanel();
p1.setLayout(null);
this.getContentPane().add(p1);
Container cont=this.getContentPane();
JScrollPane p2=new JScrollPane();
p2.setVerticalScrollBarPolicy
(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
cont.add(p1,BorderLayout.CENTER);
cont.add(p2,BorderLayout.EAST);
//显示窗口
this.setVisible(true);
public static vodi main(String[] args){
new Test1();
}
}
我想要的效果是当面板的内容超过宽度的时候,滚动条起到下拉的作用,但是这里实现不了,为什么,解解答,谢谢!!


1楼2016-06-05 17:07回复