Re: Pls Help: JMenu with 2 columns
- From: Vova Reznik <address@xxxxxxxx>
- Date: Thu, 23 Feb 2006 18:41:50 GMT
Rohit wrote:
Thanks, but that would not work for me for a number of reasons:
a) I need to have 2 different buttons:
- one that is clickable and performs an action
- another that opens a submenu that has some items that can be
clicked and perform actions
b) some LookNFeels open a menu not when you hover but only when the
user clicks on the menu itself (e.g. Motif) so this possibilty would be
problematic
Is there no way to reduce the size of those menus when they are
displayed in the popupMenu of the main Menu?
Thanks,
Rohit
Ok, the problem is in LayoutManager.
Using GridLayout will not let you have columns with different width.
I made an expiriment with SpringLayout and it works fine.
public void createAndShowMenuBar() {
load = new JMenu("Load");
load.setName("Load");
int rows = 10;
LayoutManager lm = new SpringLayout();
Container cont = load.getPopupMenu();
cont.setLayout(lm);
Dimension menuSize = new Dimension(20, 5);
for (int i = 0; i < rows; i++) {
JMenu menu = new JMenu();
menu.setPreferredSize(menuSize);
for (int j = 0; j < i; j++) {
JMenuItem menuItem = new JMenuItem("InnerItem: " + i + "." + j);
menu.add(menuItem);
}
JMenuItem menuItem = new JMenuItem("MenuItem " + i);
load.add(menuItem);
load.add(menu);
}
SpringUtilities.makeCompactGrid(cont, rows, 2, 5, 5, 5, 5);
add(load);
}
and link for SpringUtilities
http://java.sun.com/docs/books/tutorial/uiswing/layout/example-1dot4/SpringUtilities.java
.
- Follow-Ups:
- Re: Pls Help: JMenu with 2 columns
- From: Rohit
- Re: Pls Help: JMenu with 2 columns
- References:
- Pls Help: JMenu with 2 columns
- From: Rohit
- Re: Pls Help: JMenu with 2 columns
- From: Vova Reznik
- Re: Pls Help: JMenu with 2 columns
- From: Rohit
- Pls Help: JMenu with 2 columns
- Prev by Date: Re: Pls Help: JMenu with 2 columns
- Next by Date: Re: Pls Help: JMenu with 2 columns
- Previous by thread: Re: Pls Help: JMenu with 2 columns
- Next by thread: Re: Pls Help: JMenu with 2 columns
- Index(es):