[英]Adding title in a tabbed pane
Can you please help me adding title in my tabbed pane? 你能帮我在标签窗格中添加标题吗? There is no title in tabbed pane even I declared. 即使我声明,标签窗格中也没有标题。
I am creating a Frame that will have tabbed pane inside of it the tabbed pane do have panel inside of it the problem that I encountered is that I cannot add name in my tabbed pane even I use the correct method for it. 我正在创建一个框架,其中将有选项卡式窗格,选项卡式窗格内部有面板,我遇到的问题是我无法在选项卡式窗格中添加名称,即使我使用了正确的方法。
I have already tried tabbedPane.add()
, tabbedPane.addTab()
, tabbedPane.insertTab()
but none of this insert title in my tab pane. 我已经尝试过tabbedPane.add()
, tabbedPane.addTab()
, tabbedPane.insertTab()
但是我的选项卡窗格中没有这个插入标题。
JFrame f = new JFrame();
JTabbedPane tabbedPane = new JTabbedPane();
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
JLabel lb1 = new JLabel("This is first tab");
tabbedPane.addTab("Panel 1",panel1);
tabbedPane.addTab("Panel 2",panel2);
lb1.setLayout(new FlowLayout());
panel1.add(lb1);
f.setLayout(new BorderLayout());
tabbedPane.setSize(1000,600);
f.add(tabbedPane);
tabbedPane.add(panel1);
tabbedPane.add(panel2);
f.setBounds(10,20,1200,800);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
I am expecting that there will be a title on my tabbed pane. 我希望我的选项卡式窗格上会有一个标题。
JFrame f = new JFrame();
JTabbedPane tabbedPane = new JTabbedPane();
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
JLabel lb1 = new JLabel("This is first tab");
tabbedPane.addTab("Panel 1", panel1);
tabbedPane.addTab("Panel 2", panel2);
//lb1.setLayout(new FlowLayout());
panel1.add(lb1);
f.setLayout(new BorderLayout());
//tabbedPane.setSize(1000, 600);
f.add(tabbedPane);
//tabbedPane.add(panel1);
//tabbedPane.add(panel2);
f.setBounds(10, 20, 1200, 800);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
I don't know why you are: 我不知道你为什么这样:
JLabel
设置JLabel
的布局 tabbedPane
again 再次将面板添加到tabbedPane
Adding a component to a container will first remove it from it's parent, which is probably why the titles are no longer appearing 将组件添加到容器中将首先将其从父组件中删除,这可能是标题不再出现的原因
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.