Here's the problem: I have a drawing area that will display graphics (custom drawing). When the application is first started, no graphics are selected to be drawn, and the drawing area is set to a default (preferred) size. So as not to confuse the user, I'd like to display some text (something like "No Image Selected") until the real graphics are drawn. The drawing window is contained in a JScrollPane, so it can also be resized. Is there a way to add text (a JLabel?) to the drawing area and have it automatically scale to fill the extent of the drawing area?
Asked
Active
Viewed 2,107 times
2 Answers
3
You're going to want to add your JLabel to the JScrollPane Component after sizing the label's font size to your needs. See below:
jScrollPane1.setViewportView(jLabel1);
The second solution in this previous question really does a great job of laying how to scale the font size to a container... just replace the String width with your JScrollPane. Since it is inherited from JComponent, you can just use getWidth like so:
jScrollPane1.getWidth();

Community
- 1
- 1

Anthony Neace
- 25,013
- 7
- 114
- 129
2
See the link http://java-sl.com/tip_adapt_label_font_size.html
It shows how to adapt JLabel's
font size when it's resized.

StanislavL
- 56,971
- 9
- 68
- 98