I am trying to add a JLabel
to the blank space of a JTabbedPane
(to the right of the tabs and above the content panel).
I was very close with this SSCCE (using 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);
}
But, unfortunately, this SSCCE hits a MigLayout
bug (read: MigLayout error: "Unstable cyclic dependency in absolute linked values!"). If you remove the WindowsLookAndFeel
code, it gives this:
Which is precisely what I want, except it lacks the WindowsLookAndFeel
(which is a requirement for my application; MigLayout
is not). I cannot figure out how to accomplish this without MigLayout
, though.
How would you add a JLabel
to that blank space?