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