Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Position of RadioButton on the UI

Reply
Thread Tools

Position of RadioButton on the UI

 
 
wang
Guest
Posts: n/a
 
      10-21-2005
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_CLOS E);
frame.getContentPane().add(new XSheetAutomat());
frame.pack();
frame.setVisible(true);
}
}
///////////////// END CODE ///////////////////////////////

 
Reply With Quote
 
 
 
 
Vova Reznik
Guest
Posts: n/a
 
      10-21-2005
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/tutor...out/index.html
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      10-22-2005
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
advanced q?: mouseup position to caret position? brendan Javascript 0 08-29-2006 10:48 AM
detecting mouse click position in canvas tag has position off James Black Javascript 0 05-28-2006 03:27 AM
Where is Form Relative Position and Absolute Position in VS.Net 2005 ? Luqman ASP .Net 1 02-07-2006 10:27 AM
position image based on document position edouard.lauer@pt.lu Javascript 3 01-14-2006 06:04 PM
How to set position of a web control depending on other control's position at run-time? James Wong ASP .Net Web Controls 4 07-14-2004 10:24 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57