大胸美人鱼校花:JPanel 与 JFrame

来源:百度文库 编辑:高考问答 时间:2024/05/03 02:04:50
看两个例子:
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;

public class mytest extends JFrame{

JPanel panel=new JPanel();
JScrollPane scroll=new JScrollPane(panel);

public mytest(){

panel.add(new Button("188888888888888888888888"));
panel.add(new Button("288888888888888888888888"));
panel.add(new Button("388888888888888888888888"));
panel.add(new Button("488888888888888888888888"));
panel.add(new Button("188888888888888888888888"));
panel.add(new Button("288888ui8888888888888888"));
panel.add(new Button("3888888iii88888888888888"));

panel.setPreferredSize(new Dimension(200,600));
Container container=this.getContentPane();
container.setLayout(new BorderLayout());
container.add(scroll);
pack();
setSize(300,350);
setVisible(true);
}

public static void main(String args[]){
try{

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception ex){
ex.printStackTrace();
}
new mytest();

}
}

import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;

public class mytest1 extends JPanel{

JPanel panel=new JPanel();
JScrollPane scroll=new JScrollPane(panel);

public mytest1(){

panel.add(new Button("188888888888888888888888"));
panel.add(new Button("288888888888888888888888"));
panel.add(new Button("388888888888888888888888"));
panel.add(new Button("488888888888888888888888"));
panel.add(new Button("188888888888888888888888"));
panel.add(new Button("288888ui8888888888888888"));
panel.add(new Button("3888888iii88888888888888"));

panel.setPreferredSize(new Dimension(200,600));
this.add(scroll);
}

public static void main(String args[]){
try{

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception ex){
ex.printStackTrace();
}

JFrame frame=new JFrame();

frame.getContentPane().add(new mytest1());
frame.setSize(300,350);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);

}
}

如何修改使第二个例子 也能使用JScrollPane scroll的上下滚动效果!