Single Component Padding
I'm learning Java this semester at school and I'm trying to build a simple component. Basically it's a numeric label that, when clicked, switch to a textfield to let you modify the value, or if you "click-drag" the label, you can "scroll" the value like a slider.
I've set up a textfield and a label in a JPanel with a CardLayout. Works perfectly, except for one thing...
The label component always takes the maximum space available in the JPanel. That means even if the label's text is short, it's possible to click anywhere on the label to "click-drag" it, which I don't want. I want the user to click only on the actual text, or in other words, I want the label to have the same width as its text.
How can I do that?
Place the label into a JPanel that uses FlowLayout(FlowLayout.CENTER) if you want it centered. Then place that JPanel into the CardLayout using container.
Well, that was simple! Thank you!