dimanche 9 juin 2019

Java AWT: How to vertically center checkbox with flow layout next to label inside panel with gridlayout?

I am writing a little program with Java AWT.

I have a panel with GridLayout (2 columns). On the left side of the panel is a Label, on the right side a CheckboxGroup.

The CheckboxGroup is in FlowLayout. It doesn't appear on the same height as the Label. How can I adjust the height/vertically center my CheckboxGroup?

I've tried to wrap the CheckboxGroup(with FlowLayout) in a BorderLayout and set it to BorderLayout.CENTER/SOUTH.

Panel panelSelector = new Panel(new GridLayout(0,2,3,3));

HotTubLabel = new Label("Hot Tub option:");
    panelSelector.add(HotTubLabel);
    HotTubInput = new CheckboxGroup();
    Panel panelHotTubCheck = new Panel(new FlowLayout());
    panelHotTubCheck.add(new Checkbox("Yes", HotTubInput, false));
    panelHotTubCheck.add(new Checkbox("No", HotTubInput, false));
    panelHotTubCheck.add(new Checkbox("No preference", HotTubInput, true));
    panelSelector.add(panelHotTubCheck);

I expect the CheckboxGroup line to be on the same height as the Label line, just as it is with all the other objects like choice, TextField or Label.

Here a picture: Link to the picture because I don't have enough reputation ^^




Aucun commentaire:

Enregistrer un commentaire