• Post Reply Bookmark Topic Watch Topic
  • New Topic

set default radio button  RSS feed

 
sae0203
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i set a defualt button when running.
for example set the book radiobutton as the default.
book = new JRadioButton();
cd = new JRadioButton();
mag = new JRadioButton();

book.setLabel("Book");
cd.setLabel("CD-Rm");
mag.setLabel("Magazine");
pan6.add(book);
pan6.add(cd);
pan6.add(mag);
book.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseReleased(MouseEvent e) {
bookMouseReleased(e);
}
});
cd.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseReleased(MouseEvent e) {
cdMouseReleased(e);
}
});

mag.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseReleased(MouseEvent e) {
magMouseReleased(e);
}
});
 
Bal Mark
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add all your buttons to a ButtonGroup and set the button you want selected as a default selected when you begin.
This will deselect all the others ( if you use the default ButtonGroup() .. the default doesnt allow multiple selection )
/Balmark

eg.
javax.swing.JRadioButton rb1 = new javax.swing.JRadioButton();
javax.swing.JRadioButton rb2 = new javax.swing.JRadioButton();
javax.swing.JRadioButton rbBooks = new javax.swing.JRadioButton();

javax.swing.ButtonGroup bg = new javax.swing.ButtonGroup();
bg.add(rb1);
bg.add(rb2);
bg.add(rbBooks);
rbBooks.setSelected(true);
[ October 02, 2002: Message edited by: Balmark ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Balmark" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

Thanks! and welcome to the JavaRanch!
 
sae0203
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks balmark
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!