[英]How should I scale a menu size for different resolutions?
let's say I want to do a program like photoshop or lightroom in java where I work with one image on the left side and I have a menu on the right side with all the options. 假设我要在Java中执行像photoshop或lightroom之类的程序,在该程序中,我使用左侧的一个图像,而右侧使用所有选项的菜单。 How could I set the size of the panel where the menu is contained to scale correctly with multiple resolutions? 如何设置包含菜单的面板的大小,以使用多种分辨率正确缩放?
I was thinking on getting the current system resolution of the system (getScreenResolution()) and then multiply it by some factor like 0.3-0.2 and set that as width but I'm not sure if that works properly with higher resolutions or you would loose too much working space in the menu (I just have a small laptop to try). 我正在考虑获取系统的当前系统分辨率(getScreenResolution()),然后将其乘以0.3-0.2之类的系数,并将其设置为width,但是我不确定是否可以在更高的分辨率下正常工作,否则您会松懈菜单中的工作空间过多(我只有一台小型笔记本电脑可以尝试)。
I wasn't able to find any question like this, or something easier to work with the dpi in android. 我找不到类似的问题,或者在android中使用dpi时更容易使用。
I work with one image on the left side and I have a menu on the right side with all the options. 我在左侧处理一张图像,在右侧有一个菜单,其中包含所有选项。
Just use a proper layout manager and let the layout manager do its job. 只需使用适当的布局管理器,然后让布局管理器完成工作即可。
For example you can use a BorderLayout
. 例如,您可以使用BorderLayout
。
Create a panel for your menus and add that panel to the BorderLayout.LINE_END
and the panel will be displayed at its preferred size. 为菜单创建一个面板,然后将该面板添加到BorderLayout.LINE_END
,该面板将以其首选尺寸显示。
Then create a second panel for the image and add that panel to the BorderLayout.CENTER
. 然后为图像创建第二个面板,并将该面板添加到BorderLayout.CENTER
。 Now this panel will automatically be resized to fill the space as the frame is resized. 现在,此面板将自动调整大小,以在调整框架大小时填充空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.