Change Font based on screen size change

2019-09-08 06:18发布

问题:

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?

回答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>))


回答2:

GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds() ?



回答3:

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.