java - What is best way to create popup menu like in eclipse on Ctrl+F6? -
i want create popup menu same in eclipse on ctrl+f6.
it should have jscrollbar
, list of strings each item has small border.
i have idea use jdialog
how make not display border , close buttons jlist
scroll bar?
thank you!
the easiest , straightforward way use jpopupmenu
class. can add jcomponent
jpopupmenu
, not jmenuitem
s.
here's button when clicked, shows jlist
in popup without close buttons, scroll bar. wherever popup (the jlist
) loses focus, popup automatically closed.
final jbutton b = new jbutton("press me"); b.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent e) { final defaultlistmodel<string> model = new defaultlistmodel<>(); (int = 0; < 100; i++) model.addelement(i + "."); final jlist<string> l = new jlist<>(model); final jpopupmenu pm = new jpopupmenu(); final jscrollpane sp = new jscrollpane(l); // pm.setpreferredsize(new dimension(100, 300)); pm.add(sp); pm.show(b, 0, 0); } });
Comments
Post a Comment