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 ///////////////////////////////
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 ///////////////////////////////