JRadioButton.setHorizontalAlignment() not working?
Hi,
I'm trying to get some JRadioButtons to line up down the left side of a JFrame. The problem is they seem to always end up placed with the buttons in the middle, and the text to the right. Any ideas?
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
class Exampleextends JFrame
{
JRadioButton allRadioButton;
JRadioButton uncollectionedRadioButton;
JRadioButton subsetRadioButton;
JButton okButton;
JButton cancelButton;
public Example()
{
this.addWindowListener(new WindowAdapter()
{
publicvoid windowClosing(WindowEvent e)
{
dispose();
}
});
setTitle("Collection Chooser");
Container c = this.getContentPane();
c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS));
allRadioButton =new JRadioButton("all images");
uncollectionedRadioButton =new JRadioButton("uncollectioned images");
subsetRadioButton =new JRadioButton("subset of collections...");
ButtonGroup collectionButtonGroup =new ButtonGroup();
collectionButtonGroup.add(allRadioButton);
collectionButtonGroup.add(uncollectionedRadioButton);
collectionButtonGroup.add(subsetRadioButton);
allRadioButton.setHorizontalAlignment(JRadioButton.LEFT);
uncollectionedRadioButton.setHorizontalAlignment(JRadioButton.LEFT);
subsetRadioButton.setHorizontalAlignment(JRadioButton.LEFT);
c.add(allRadioButton);
c.add(uncollectionedRadioButton);
c.add(subsetRadioButton);
setSize(150, 120);
okButton =new JButton("ok");
cancelButton =new JButton("cancel");
JPanel buttonPanel =new JPanel();
buttonPanel.setLayout(new GridLayout(1,2));
buttonPanel.add(okButton);
buttonPanel.add(cancelButton);
c.add(buttonPanel);
JFrameUtilities.center(this);
setAlwaysOnTop(true);
setResizable(false);
setVisible(true);
}
}

