質問

I am trying to make a menu of a restaurant and the reason I am putting this question is because I want to have 4 panels using border layout.I am having 4 panels each of them named westPanel,topPanel,eastPanel and bottomPanel.I have already made the JRadioButtons as I want to and put them in a button group.I have made 2 of buttons groups and I want to put one button group of JRadioButtons in the west and the other on the east.Or maybe a JComboBox on the eastPanel.The problem is that when I am trying to do so by the method :

eastpanel.add(ButtonGroup(nameofgroup), BorderLayout.EAST)

says it is an error for the components of ButtonGroups.Is there any way that I can put the group in the panels or just the radio buttons?

役に立ちましたか?

解決

ButtonGroup is not a component, so it cannot be added to the panel. You need to add the individual components.

Your question is not very clear so I am not exactly sure what you are trying to achieve.

JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
buttonPanel.add(radio1);
buttonPanel.add(radio2);
eastpanel.add(buttonPanel, BorderLayout.EAST)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top