面板
package Demo02;
import java.awt.Container;
//面板作为容器不能单独存在,必须放到其他容器里面JFrame,jDialog
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class JPaneDemo extends JFrame{
public JPaneDemo() {
Container container1=this.getContentPane();
container1.setLayout(new GridLayout(2,1,10,10));//布局行列,间距
JPanel panel=new JPanel(new GridLayout(1,3));
panel.add(new JButton("1"));
panel.add(new JButton("2"));
panel.add(new JButton("3"));
container1.add(panel);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
this.setBounds(100,100,500,500);
}
public static void main(String[] args) {
new JPaneDemo();
}
}
文本域
package Demo02;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class JScrollDemo extends JFrame{
public JScrollDemo() {
Container container1=this.getContentPane();
//文本域
JTextArea texarea=new JTextArea(20,50);
texarea.setText("大数据2005");
//scroll面板
JScrollPane scrollpane=new JScrollPane(texarea);
//JScrollDemo scrollDemo=new JPanel();
//scrollDemo.add(textarea);
container1.add(scrollpane);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
this.setBounds(100,100,500,500);
}
public static void main(String[] args) {
new JScrollDemo();
}
}
窗体布局