Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Scrollable JMenu?

558 views
Skip to first unread message

Kevin Nix

unread,
Nov 30, 2001, 11:48:56 AM11/30/01
to
Being a Java rookie, I'm not too sure if the subject line is possible.

Basically, I have a JMenu that contains so many items that it has become
quite unwieldy. All the items under this particular menu would be very
difficult to sub-categorize. Is a scrollable JMenu out of the question? If
not, a code snippet implementation example would be much appreciated....

Thanks, K


Paul Lutus

unread,
Nov 30, 2001, 12:45:16 PM11/30/01
to
"Kevin Nix" <kn...@nortelnetworks.com> wrote in message
news:9u8d9q$1ks$1...@bcarh8ab.ca.nortel.com...

This is not such a good idea, because people do not expect it. Why not
create submenus instead, and figure out how to categorize the items? Like
the example below -- it has 1296 JMenuItems, not counting all the JMenus
that form the tree, and it is not crowded the same way yours is (it's
crowded differently):

// MenuTree.java

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class MenuTree extends JFrame {

int max = 3;
public MenuTree()
{
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
}
);

String[] cardinals = new String[]
{"North","South","East","West","Center"};

JPanel panel = new JPanel();

panel.setLayout(new BorderLayout());
for(int i = 0;i < cardinals.length;i++) {
panel.add(cardinals[i],new JButton(cardinals[i]));
}

getContentPane().add(panel,BorderLayout.CENTER);

JMenuBar bar = new JMenuBar();
setJMenuBar(bar);

JMenu menu = new JMenu("Really deep menu!");
bar.add(menu);

buildMenu(menu,0,"");

setSize(500,400);

setVisible(true);
}

// recursively build menu tree

void buildMenu(JMenu menu,int n,String label) {
ButtonGroup bg = new ButtonGroup();
for(int i = 1;i <= 6;i++) {
if(n < max) {
JMenu m = new JMenu("Menu " + label+i);
buildMenu(m,n+1,label+i);
menu.add(m);
}
else {
JRadioButtonMenuItem m = new JRadioButtonMenuItem("MenuItem " +
label+i,(i == 1));
menu.add(m);
bg.add(m);
}
}
}

public static void main(String args[])
{
new MenuTree();
}
}

Another approach is a clickable tree display, but this also requires you to
figure out how to group your items into categories and subcategories.

--
Paul Lutus
www.arachnoid.com


MSeries

unread,
Dec 2, 2001, 5:53:17 AM12/2/01
to
This is not out of the question. Disregard what others say, if your
application demands it then you need to do it. I saw such a component at a
presentation at JavaOne in June, I vowed to write one for public domain and
so far have done diddly squat !

Please email me if you wish to discuss it. seth_b...@bigfoot.com


Check out my other components at http://web.ukonline.co.uk/mseries


"Kevin Nix" <kn...@nortelnetworks.com> wrote in message
news:9u8d9q$1ks$1...@bcarh8ab.ca.nortel.com...

Paul Lutus

unread,
Dec 2, 2001, 12:28:19 PM12/2/01
to
"MSeries" <seth_brundell@bigf**t.com> wrote in message
news:9ud169$v2f$1...@newsg4.svr.pol.co.uk...

> This is not out of the question. Disregard what others say, if your
> application demands it then you need to do it.

False. Computer programs should live up to the users' common-sense
expectations. Your proposal puts the whims of the programmer above the needs
of the user.

This is why there are coding guidelines in Java. Computer programming is
supposed to be a cooperative endeavor -- cooperation between programmers,
and between programmer and user.

Menus should act like menus. And the OP needs to figure out how to break his
list up into categories, no matter how he packages the result.

--
Paul Lutus
www.arachnoid.com


MSeries

unread,
Dec 2, 2001, 4:36:51 PM12/2/01
to
Not rising

"Paul Lutus" <nos...@nosite.zzz> wrote in message
news:TwtO7.44132$ox2.3...@bin4.nnrp.aus1.giganews.com...

0 new messages