Change Font based on screen size change

2019-09-08 06:47发布

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?

3条回答
太酷不给撩
2楼-- · 2019-09-08 06:54

GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds() ?

查看更多
贼婆χ
3楼-- · 2019-09-08 06:56

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>))
查看更多
等我变得足够好
4楼-- · 2019-09-08 07:11

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.

查看更多
登录 后发表回答