java - JComboBox to display multiple lines of text -


i'm writing small tool sending sql queries database , recieving according data.

now problem: want allow user enter new search query or select "latest" list, last few queries saved. that, planned on using editable jcombobox, i'm having trouble diplaying multiple lines of text in box itself.

the reason want that, because sql queries can quite long , since want make box editable , @ same time keep frame clean.

i've found ways display multiple lines in dropdown menu, nothing box itself.

thank in advance , please forgive me if overlooked simple ;)

greetings zeus

extended editing functionality supplied comboboxeditor, allows define actual component used combobox's editor

based on requirements, you're going need (at least) jtextarea, provide (optionally) word wrapping , multiple lines

a rough , ready example might this...

public class textareacomboboxeditor implements comboboxeditor {      private jtextarea ta = new jtextarea(4, 20);     private jscrollpane sp = new jscrollpane(ta);      public textareacomboboxeditor() {         ta.setwrapstyleword(true);         ta.setlinewrap(true);     }      @override     public component geteditorcomponent() {         return sp;     }      @override     public void setitem(object anobject) {         if (anobject instanceof string) {             ta.settext((string) anobject);         } else {             ta.settext(null);         }     }      @override     public object getitem() {         return ta.gettext();     }      @override     public void selectall() {         ta.selectall();     }      @override     public void addactionlistener(actionlistener l) {     }      @override     public void removeactionlistener(actionlistener l) {     }  } 

this doesn't support actionlistener, jtextarea uses enter key it's own purposes. if wanted to, use key bindings api add own action can trigger actionlisteners, that, you'd need supply list or other means managing them can call them back


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -