I made a combobox but some of the elements are wider than the width of my box. So I tried to add a horizontal scrolpane and the only I could see is a scrolpane with a combobox inside! Certanly something I do wrong. So here is my code without the jscrolpane.
issuerdocumentJComboBox=new JComboBox<>(issuermodel);//the compo box
issuerdocumentJComboBox.setBounds(430, 120, 100, 30);
searchDocumentesJPanel.add(issuerdocumentJComboBox);
How can I add to the combobox a horizontal scrollpane? Thank you!
It is possible!! Here's a little program I wrote to show my solution:
The approach is to create a custom ComboBoxEditor that displays the JTextField editor in a scroll pane (easier to just extend BasicComboBoxEditor). The
getEditorComponent()
function is then overridden to return the scroll pane instead of the text field.These two overidden functions are called internally when you call
combobox.setEditor(new MyEditor())
so don't worry if you can't see it being used.Here's a screenshot of the program showing an element wider than combobox:
GOODLUCK!! :-)