【发布时间】:2014-10-18 19:11:37
【问题描述】:
我正在尝试将JLabel 添加到JTabbedPane 的空白处(在选项卡的右侧和内容面板的上方)。
我非常接近这个 SSCCE(使用MigLayout):
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
JFrame frame = new JFrame();
frame.setLayout(new MigLayout(new LC().fill().insetsAll("0")));
JTabbedPane jtp = new JTabbedPane();
jtp.add(new JPanel(), "Tab 1");
jtp.add(new JPanel(), "Tab 2");
JLabel label = new JLabel("label");
JPanel panel = new JPanel(new MigLayout(new LC().fill()));
panel.add(jtp, "id tabbedpane, grow, span");
panel.add(label, "pos (tabbedpane.w-label.w) 10, id label");
label.setBounds(100, 100, 10, 10);
frame.add(panel, "grow, span");
frame.setSize(500, 500);
frame.setLocationRelativeTo(null); // Sorry, Andrew Thompson
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
但是,不幸的是,这个 SSCCE 遇到了 MigLayout 错误(阅读:MigLayout error: "Unstable cyclic dependency in absolute linked values!")。如果您删除 WindowsLookAndFeel 代码,它会给出:
这正是我想要的,除了它缺少 WindowsLookAndFeel(这是我的应用程序的要求;MigLayout 不是)。不过,如果没有MigLayout,我无法弄清楚如何实现这一点。
如何在该空白处添加JLabel?
【问题讨论】:
-
为什么布局这么糟糕?为什么不用 JLayer?
标签: java swing layout-manager jtabbedpane