【问题标题】:Java JTabbedPane only see one tabJava JTabbedPane 只看到一个选项卡
【发布时间】:2020-04-23 08:19:28
【问题描述】:

我正在制作 een tabbedpane,但所有选项卡都在彼此之上,或者只有添加。但我找不到解决方案。

这是我的代码:

public Frame(int width, int height) {
    setSize(width, height);

    setTitle("NerdyGadgets backoffice");
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JLabel label = new JLabel("test the label");
    JTabbedPane tabbedPane = new JTabbedPane();

    tabbedPane.addTab("firstpane", label);
    tabbedPane.addTab("secondpane", label);
    tabbedPane.addTab("test", null, label, "test test test");

    add(tabbedPane);
    setVisible(true);
}

这是我得到的结果: https://gyazo.com/4027807aa305beb227ca4a402d43f067

【问题讨论】:

  • 不要重复使用标签 - 它只能属于单个父容器

标签: java swing jtabbedpane


【解决方案1】:

一个组件只能属于一个父级,这意味着在您的情况下,它只会应用于最后一个选项卡

setLayout(new BorderLayout());
JLabel label = new JLabel("test the label");
JTabbedPane tabbedPane = new JTabbedPane();

tabbedPane.addTab("firstpane", new JLabel("Tab 1"));
tabbedPane.addTab("secondpane", new JLabel("Tab 2"));
tabbedPane.addTab("test", null, label, "test test test");

add(tabbedPane);

【讨论】:

  • 谢谢,不知道这个
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-30
  • 1970-01-01
  • 2017-03-09
  • 1970-01-01
相关资源
最近更新 更多