1

I have a problem. I have huge gap between the Label and radiobuttons but I dont want to have the gaps. I think it is because of my Layout but I am not sure.

Importent: Below this is a Picture. Picture has more to say then words^^

Huge Gap and the Radiobutton is in the center bottom

"Action choose" is in the correct position. Now I just want to show the Radiobutton underneath of "Action choose". In the position of the 'c' of "Action choose". But this is not important.

This is my Code how I create this type of styling. :)

   JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));

    panel.add(new Label("Action choose:"));
JRadioButton action1 = new JRadioButton("Anime",false);
JRadioButton action2 = new JRadioButton("AMV",false);
JRadioButton action3 = new JRadioButton("OVA",false);
JRadioButton action4 = new JRadioButton("Manga",false);
ButtonGroup group = new ButtonGroup();
    group.add(action1);
    group.add(action2);
    group.add(action3);
    group.add(action4);

    panel.add(action1);
    panel.add(action2);
    panel.add(action3);
    panel.add(action4);

Best Regards

Kuku

KukuBra
  • 33
  • 1
  • 6
  • 1
    The picture shows how it looks like, but not how it should be, and please, provide a valid [mcve] that we can copy-paste and see your issue – Frakcool Jun 29 '17 at 17:19
  • I am not so good in photoshop to show of but I descripe it in my post now. – KukuBra Jun 29 '17 at 17:49

1 Answers1

1
panel.add(new Label("Action choose:"));

Don't use a Label. That is an AWT component.

Use a JLabel for Swing a application.

A BoxLayout will respect the maximum size of a component. For a JLabel the maximum size is the same as the preferred size. For a Label, there is no maximum size so the label will take as much space as possible.

camickr
  • 321,443
  • 19
  • 166
  • 288