Hi,
You may do it this way .
Please note that this example ran fine with JRE 1.4 , but quite strangely
with 1.5 (i.e, couldn't select a radiobutton with the mouse, only with the
space key / scrolling was very very hard).
Well if anyone knows the reason for such a difference, it would be great.
public class temp1 extends JFrame {
public temp1() {
super("Scroll Test");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel contentPane = new JPanel(new BorderLayout());
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p,BoxLayout.Y_AXIS));
ButtonGroup group=new ButtonGroup();
for (int j = 0; j < 40; j++){
JRadioButton button=new JRadioButton(new String(j + ""));
p.add(button);
group.add(button);
button.setSelected(true);
}
JScrollPane sp = new JScrollPane(p);
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Scroll");
sp.setPreferredSize(new Dimension(100, 100));
menu.add(sp);
menu.add(new JMenuItem("Hello"));
menuBar.add(menu);
this.setJMenuBar(menuBar);
this.setSize(300, 300);
}
public static void main(String[] args) {
JFrame j = new temp1();
j.show();
}
}
Regards,
Arnaud
> Hi,
> I am trying to create a menu which has RadiobuttonMenuItems displayed
[quoted text clipped - 38 lines]
> Thanks
> Krishnan
KrishRads Venkat - 18 May 2005 10:42 GMT
Thanks Arnaud for your speedy response.Yeah the scrolable radio buttons
worked fine.But what I was trying to have are JRadiobuttonMenuItems not
JRadioButtons.I tried replacing the latter with the former.The butons were
being displayed alright but the window used to shut as soon as I tried to
scroll.I wonder if we could JRadioButtonMenuItems directly to the panel
rather than to a JMenu.
Please advise.
Thanks once again.
Arnaud Berger - 18 May 2005 10:53 GMT
Menuitems are probably meant to be added to menus only.
I couldn't say how predictable their behavior may be if added to anything
else.
Why would you absolutely need JRadioButtonMenuItems rather than
JRadioButtons ?
Regards,
Arnaud
> Thanks Arnaud for your speedy response.Yeah the scrolable radio buttons
> worked fine.But what I was trying to have are JRadiobuttonMenuItems not
[quoted text clipped - 10 lines]
> Message posted via JavaKB.com
> http://www.javakb.com/Uwe/Forums.aspx/java-gui/200505/1