Answer the question
In order to leave comments, you need to log in
How to get the width of a JComboBox dropdown button in Swing?
Hello. There was a need to get the width of the combobox button (JComboBox). Haven't found how to do it yet. Can someone suggest?
PS This is necessary to set the combobox width to match the length of the currently displayed text (the text representation of the currently selected item). And then, if the list has a lot of rows of small length, and there is a large string, then the combobox turns out to be very wide, and it looks ugly (and it may not enter the screen or take up a lot of space on the screen)
Answer the question
In order to leave comments, you need to log in
As a result, I solved my problem by calling the "public void setPrototypeDisplayValue(E prototypeDisplayValue)" method on the JComboBox class object. This, of course, does not answer the question I asked, but it solves the original problem that caused me to ask this question.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question