Position of RadioButton on the UI

W

wang

Hi all,
in the following program I expect the JRadioButtons
be placed on the left edge. But they start at the center.
What should be done to "move" them to the left? Thanks.
k.w.wang

////////////// BEGIN CODE /////////////////////////
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class XSheetAutomat extends JPanel
implements ActionListener {

JRadioButton deleteProc;
JRadioButton deleteNone;
ButtonGroup group;
JTextArea report;
static String txtDelProc = "DeleteProcessed";
static String txtDelNone = "DeleteNone";
static String txtStart = "start";
static String txtExit = "exit";
JButton start;
JButton exit;

public XSheetAutomat() {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

JPanel decisionPanel = new JPanel();
JLabel decisionText = new JLabel(
"What will you do with the source files after the processing?");
decisionPanel.add(decisionText);

// radio buttons
JPanel radioPanel = new JPanel();
radioPanel.setLayout(new BoxLayout(radioPanel, BoxLayout.Y_AXIS));

deleteProc = new JRadioButton("Delete processed source files");
deleteProc.setMnemonic(KeyEvent.VK_P);
deleteProc.setActionCommand(txtDelProc);
deleteProc.addActionListener(this);
deleteProc.setSelected(true);

deleteNone = new JRadioButton("Don't delete any file");
deleteNone.setMnemonic(KeyEvent.VK_N);
deleteNone.setActionCommand(txtDelNone);
deleteNone.addActionListener(this);

group = new ButtonGroup();
group.add(deleteProc);
group.add(deleteNone);

radioPanel.add(deleteProc);
radioPanel.add(deleteNone);

// processing message
report = new JTextArea(20, 60);
report.setEditable(false);
report.setLineWrap(true);
report.setWrapStyleWord(true);
JScrollPane scrollPane =
new JScrollPane(report,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
// buttons
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel,
BoxLayout.X_AXIS));

start = new JButton("Start");
start.setMnemonic(KeyEvent.VK_S);
start.setActionCommand(txtStart);
start.addActionListener(this);

exit = new JButton("Exit");
exit.setMnemonic(KeyEvent.VK_X);
exit.setActionCommand(txtExit);
exit.addActionListener(this);

buttonPanel.add(start);
buttonPanel.add(exit);

this.add(decisionPanel);
this.add(radioPanel);
this.add(scrollPane);
this.add(buttonPanel);
}

public void actionPerformed(ActionEvent e) {
}

public static void main(String[] args) {
JFrame frame = new JFrame("X-Sheet Automation");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new XSheetAutomat());
frame.pack();
frame.setVisible(true);
}
}
///////////////// END CODE ///////////////////////////////
 
V

Vova Reznik

wang said:
Hi all,
in the following program I expect the JRadioButtons
be placed on the left edge. But they start at the center.
What should be done to "move" them to the left? Thanks.
k.w.wang

////////////// BEGIN CODE /////////////////////////
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class XSheetAutomat extends JPanel
implements ActionListener {

JRadioButton deleteProc;
JRadioButton deleteNone;
ButtonGroup group;
JTextArea report;
static String txtDelProc = "DeleteProcessed";
static String txtDelNone = "DeleteNone";
static String txtStart = "start";
static String txtExit = "exit";
JButton start;
JButton exit;

public XSheetAutomat() {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

JPanel decisionPanel = new JPanel();
JLabel decisionText = new JLabel(
"What will you do with the source files after the processing?");
decisionPanel.add(decisionText);

// radio buttons
JPanel radioPanel = new JPanel();
radioPanel.setLayout(new BoxLayout(radioPanel, BoxLayout.Y_AXIS));

Add this - it will explain
radioPanel.setBorder(new EtchedBorder());

Also read this
http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html
 

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top