Stack Exchange
Display bug with HTML in a JLabel with GridBagLayout
I have a weird bug with HTML in a JLabel and GridBagLayout at the top component hierarchy. Here is an short example showing the bug :
JFrame frame = new JFrame();
frame.setLayout(new GridBagLayout());
JPanel panel = new JPanel(new FlowLayout());
JPanel panelIn = new JPanel(new FlowLayout());
panelIn.add(new JLabel("<html># Test</html>"));
panel.add(panelIn);
panel.add(new JButton("Test"));
frame.add(panel, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));

frame.setSize(100, 100);
frame.setLocationRelativeTo(null);
frame.setVisible(true);

When I run this code, the button is not displayed. However, if I put <html>Test</html> instead of <html># Test</html>, it works.
Can you explain this bug ?

When you removed the hash, there was enough room for both components, since one of the components became less in width. Use GridBagLayout for all panels and replace the frame.setSize(100, 100); with frame.pack().

Oups... You're right! My real problem was a little bit more complicated but it was indeed a panel size issue... Thanks!
