Search code examples
javaswingjscrollpanejcomboboxcustom-component

How can one resize the scrollelements of a JComboBox?


I have a few JComboBoxes in my programm. I want to change the size of the scrollbar and the arrow button in the way that they are much wider. I need that because I want to use the programm on a Windows tablet and it is too small for a finger to work with. Is there any possibility to do that?

enter image description here

JComboBox comboBox;
comboBox = new JComboBox(list_apple_device.toArray());
comboBox.setSelectedItem(null);
comboBox.setFont(schrift);
comboBox.setBounds(1568, 329, 306, 43);
comboBox.addItemListener(new ItemListener() {
    @Override
    public void itemStateChanged(ItemEvent e) {
        // TODO Auto-generated method stub
        textField.setText(""+e.getItem());
    }
});
getContentPane().add(comboBox);

That's my code.


Solution

  • You can use the UIManger to control the width of the scrollbar:

    UIManager.put("ScrollBar.width", new Integer(50));
    

    You would execute that code BEFORE you create the combo box.