JPanel 可以添加JPanel 吗?一个JTabbedPane的标签中可以添加多少JPanel?
importjava.awt.*;importjavax.swing.*;publicclassTestTab{privateJFramejf=newJFrame();p...
import java.awt.*;
import javax.swing.*;
public class TestTab
{
private JFrame jf = new JFrame();
private JPanel p1 = new JPanel(new GridLayout(1,3));
private JPanel p2 = new JPanel(new GridLayout(1,2));
private JPanel p3 = new JPanel(new BorderLayout());
private JButton bt = new JButton("test");
private JTabbedPane jt = new JTabbedPane();
public TestTab()
{
for(int i = 0; i < 3; i++)
p1.add(bt);
for(int i = 0; i < 2; i++)
p2.add(bt);
p3.add(p2,BorderLayout.NORTH);
p3.add(p1,BorderLayout.SOUTH);
jt.add("abc",p3);
jf.add(jt);
jf.setVisible(true);
jf.setSize(100, 100);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new TestTab();
}
}
这段代码的运行结果为什么不是预期的?而是这样的 展开
import javax.swing.*;
public class TestTab
{
private JFrame jf = new JFrame();
private JPanel p1 = new JPanel(new GridLayout(1,3));
private JPanel p2 = new JPanel(new GridLayout(1,2));
private JPanel p3 = new JPanel(new BorderLayout());
private JButton bt = new JButton("test");
private JTabbedPane jt = new JTabbedPane();
public TestTab()
{
for(int i = 0; i < 3; i++)
p1.add(bt);
for(int i = 0; i < 2; i++)
p2.add(bt);
p3.add(p2,BorderLayout.NORTH);
p3.add(p1,BorderLayout.SOUTH);
jt.add("abc",p3);
jf.add(jt);
jf.setVisible(true);
jf.setSize(100, 100);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new TestTab();
}
}
这段代码的运行结果为什么不是预期的?而是这样的 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询