0

In my Java Swing application, I have buttons. If the screen size is changed, I want to change the font of my button text also.

How do I implement it?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Tvd
  • 4,463
  • 18
  • 79
  • 125
  • what do you mean by "screen size"? Mine is fixed, looking at it :-) – kleopatra Nov 18 '11 at 10:58
  • By Screen size, I mean user can resize the screen. If he changes teh screen size then the font of buttons should be changed automatically. – Tvd Nov 18 '11 at 11:31
  • still don't understand: do you have futuristic hardware or do you mean the JFrame that's showing your application _on the screen_? – kleopatra Nov 18 '11 at 11:38
  • @kleopatra I mean the JFrame that's showing. If the window is resized, I want to change the font size. Whats the best approach to change font based on what settings it should be done. How to calculate the font size based on screen size. Like if the screen is 200*200 then 14 size is good. If the screen turns 450*450 then how should the font size be calcuated and where should be added to set the font for all componetns. – Tvd Nov 18 '11 at 11:53
  • duplicated? http://stackoverflow.com/questions/8183949/swing-scale-a-text-font-of-component – kleopatra Nov 18 '11 at 14:33

3 Answers3

1

I believe that you need a JFrame window listener and simply change the button attributes there:

//global JButton button1 defined earlier
button1.setFont(new Font("<FONT NAME>", <FONT STYLE>, <FONT SIZE>))
psukys
  • 387
  • 2
  • 6
  • 20
0

GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds() ?

StanislavL
  • 56,971
  • 9
  • 68
  • 98
0

Thanks to all,

Based on listeners and frame size, border size and actual panel size I have figured font sizes for various screen size ranges.

Tvd
  • 4,463
  • 18
  • 79
  • 125