Position of RadioButton on the UI

Discussion in 'Java' started by wang, Oct 21, 2005.

  1. wang

    wang Guest

    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 ///////////////////////////////
     
    wang, Oct 21, 2005
    #1
    1. Advertising

  2. wang

    Vova Reznik Guest

    wang wrote:
    > 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
     
    Vova Reznik, Oct 21, 2005
    #2
    1. Advertising

  3. wang

    Roedy Green Guest

    On 21 Oct 2005 14:07:38 -0700, "wang" <> wrote or
    quoted :

    > 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

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Oct 22, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luqman
    Replies:
    1
    Views:
    657
    Luqman
    Feb 7, 2006
  2. James Wong
    Replies:
    4
    Views:
    503
    James Wong
    Jul 14, 2004
  3. Replies:
    3
    Views:
    184
  4. James Black
    Replies:
    0
    Views:
    403
    James Black
    May 28, 2006
  5. brendan
    Replies:
    0
    Views:
    199
    brendan
    Aug 29, 2006
Loading...

Share This Page