[問題] 使用多個panel不使用layout時遇到的問題
簡單來說,我先建一個JFrame當主視窗(使用FlowLayout)
然後想在裡面放一個JPanel p (不使用Layout)
但不知道為什麼就是顯示不出來,希望有人能幫忙解惑一下...
小弟程式碼如下:
01 import javax.swing.*;
02 import java.awt.*;
03 import java.awt.event.*;
04
05 public class test extends JFrame{
06 private Container c;
07 private JPanel p;
08
09 public test(){
10 super("123");
11 c = getContentPane();
12 c.setLayout( new FlowLayout() );
13 p = new JPanel();
14 p.setLayout(null);
15 JButton b4 = new JButton("four");
16 p.add(b4);
17 b4.setBounds(20, 20, 80, 80);
18 p.setSize(100,100);
19 p.setBackground(Color.orange);
20 p.setVisible(true);
21 c.add(p);
22 c.validate();
23
24 setSize(400,400);
25 show();
26 }
27 public static void main(String args[]){
28 test app = new test();
29 }
30 }
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.247.26
推
08/28 22:42, , 1F
08/28 22:42, 1F
→
08/28 23:09, , 2F
08/28 23:09, 2F
→
08/29 00:13, , 3F
08/29 00:13, 3F