openlcb / OpenLCB_Java

A git-managed copy of the SVN-based Java prototype implementation of OpenLCB. This implementation operates inside JMRI.
6 stars 9 forks source link

Automate sizing of NodeSelector JComboBox #216

Closed bobjacobsen closed 1 year ago

bobjacobsen commented 1 year ago

This changes the handling of the JComboBox in org.openlcb.swing.NodeSelector so that it automatically sizes itself to the largest selection string available when the NodeSelector is created.

balazsracz commented 1 year ago

I don't see any code to resize the combo box when there are nodes. The only code seems to be active when node count == 0. So how does this work?

bobjacobsen commented 1 year ago

A JComboBox by default has a preferred size that will hold its longest content. That's used by a pack() call during layout, so it'll be that size unless there are external constraints.

The previous code was overriding that behavior by always by setting a manual size. I removed that to allow the default behavior to work, setting it specifically only when there isn't any content. That's needed because the default-no-content size is 20 characters, smaller than our typical identifiers.