I have a JMenu
which will include JMenuItem
s that are generated on start-up from a database. As such, it's quite likely that the menu will be too large and run off the screen.
As such, I am trying to add a JScrollPane
to the JMenu
.
Example, to the effect of;
JMenu employeesMenu = new JMenu("Employees");
JScrollPane emScroll = new JScrollPane();
JList contents = new JList();
contents.add(new JRadioButton("1"));
contents.add(new JRadioButton("2"));
contents.add(new JRadioButton("3"));
// ... etc
emScroll.add(contents);
employeesMenu.add(emScroll);
Now, my understanding is that a JMenu
's contents are stored in a JList
inside a JPopupMenu
. So my question now is, what is a way of forcing that JList
into a JScrollPane
? Alternatively, is it possible to use a JScrollBar instead? Any input appreciated.
question from:
https://stackoverflow.com/questions/65545543/how-do-i-create-a-scrolling-jmenu 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…