放大Java Swing应用程序 [英] Zoom in Java Swing application

查看:137
本文介绍了放大Java Swing应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找放大Java Swing应用程序的方法。这意味着我希望通过给定因子调整给定JPanel中的所有组件的大小,就好像我将截取UI并仅应用图像缩放操作一样。必须调整字体大小以及复选框,文本框,光标等的大小。
可以通过将变换应用于图形对象来缩放组件:

I am looking for ways to zoom in a Java Swing application. That means that I would like to resize all components in a given JPanel by a given factor as if I would take an screenshot of the UI and just applied an "Image scale" operation. The font size as well as the size of checkboxes, textboxes, cursors etc. has to be adjusted. It is possible to scale a component by applying transforms to a graphics object:

 protected Graphics getComponentGraphics(Graphics g) {
  Graphics2D g2d=(Graphics2D)g;

  g2d.scale(2, 2);

  return super.getComponentGraphics(g2d);
 }

只要您不关心自我更新组件,这就有效。如果您的应用程序中有一个文本框,则此方法将停止工作,因为文本框每秒更新一次以显示(闪烁)光标。并且由于此时它不使用修改的图形对象,因此组件出现在旧位置。是否有可能永久更改组件图形对象?鼠标单击事件处理程序也存在问题。
另一种可能性是将JPanel的所有子组件(setPreferredSize)调整为新大小。这对复选框不起作用,因为复选框的显示图片不会改变其大小。
我还想过编写自己的布局管理器,但我认为这不会起作用,因为布局管理器只改变对象的位置(和大小),但是无法放大复选框(参见上一段)。或者我错了这个假设?
您是否有任何想法如何在不编程自定义组件的情况下实现可缩放的Swing GUI?我寻找可旋转的用户界面,因为问题似乎很熟悉,但我也没有找到任何令人满意的解决方案。

That works as long as you don't care about self-updating components. If you have a textbox in your application this approach ceases to work since the textbox updates itself every second to show the (blinking) cursor. And since it doesn't use the modified graphics object this time the component appears at the old location. Is there a possibility to change a components graphics object permanently? There is also a problem with the mouse click event handlers. The other possibility would be to resize all child components of the JPanel (setPreferredSize) to a new size. That doesn't work for checkboxes since the displayed picture of the checkbox doesn't change its size. I also thought of programming my own layout manager but I don't think that this will work since layout managers only change the position (and size) of objects but are not able to zoom into checkboxes (see previous paragraph). Or am I wrong with this hypothesis? Do you have any ideas how one could achieve a zoomable Swing GUI without programming custom components? I looked for rotatable user interfaces because the problem seems familiar but I also didn't find any satisfying solution to this problem.

感谢您的帮助,
Chris

Thanks for your help, Chris

推荐答案

你可以试试 JXLayer库

里面有几个工具可以帮助你进行缩放。查看示例此处显示。我建议你从这个库中阅读有关TransformUI的更多信息。从示例中,它似乎可以帮助解决您的问题。

There are several tools in it, which could help you to make a zoom. Check the examples shown here. I would recommend you to read more about the TransformUI, from this library. From the example, it seems like it could help solving your problem.

这篇关于放大Java Swing应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆