JRadioButton help

G

gtmeloney

I am trying to create a java application with several JButtons, a
JTextField and 6 JRadioButtons. I am trying to use only 1 panel but am
unable to get anything to show up besides the JButtons. I am trying to
use no layout manager so I can position things myself absolutely. I'm
pretty sure that my problem is something to do with
"myPanel.setLayout(null)". But any help would be appreciated. Thanks


JFrame myFrame = new JFrame ("Conversion Gui (TEST)");
myFrame.setDefaultLookAndFeelDecorated (false);
myFrame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);



JRadioButton radBtn1 = new JRadioButton ("Button 1");
JRadioButton radBtn2 = new JRadioButton ("Button 2");

radBtn1.setLocation (100,200);


ButtonGroup bg = new ButtonGroup();
bg.add(radBtn1);
bg.add(radBtn2);

myPanel = new JPanel();
myPanel.setLayout(null);

myPanel.add(radBtn1);
myPanel.add(radBtn2);

radBtn2.setLocation (200,300);

myFrame.add(myPanel);
myFrame.pack();
myFrame.setSize (500,500);
myFrame.setVisible(true);
 
G

gtmeloney

So apparently, all I was missing was a setSize call for each of my
radio buttons and text fields. My new code includes

radBtn1.setSize (75, 25);
myField.setSize (300, 27);

Both the JRadioButtons and JTextFields appear and I am able to move
them via pixel coordinates.
 
A

Andrew Thompson

"myPanel.setLayout(null)".

A 'null' layout is usually an extraordinarily bad choice.

If there is any logic to the layout whatsoever, it is best
to wrap that logic in a custom layout. Even if that is a
'DragItWhereverIWantItLayout'.

Andrew T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top