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 ///////////////////////////////
Vova Reznik - 21 Oct 2005 22:51 GMT
> Hi all,
> in the following program I expect the JRadioButtons
[quoted text clipped - 32 lines]
> 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
Roedy Green - 22 Oct 2005 03:15 GMT
> setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
Positioning is also function of your Layout, not just the radio
buttons themselves. Read up on details of BoxLayout positioning. If
it won't give you the control you need, ramp up to a more complex
layout.
See http://mindprod.com/jgloss/layout.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.