简体   繁体   English

我应该如何缩放菜单大小以适应不同的分辨率?

[英]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.

相关问题 无法在不同的屏幕分辨率下缩放文本大小 - Can't Scale Text Size on Different Screen Resolutions 如何使用ViewPorts在libgdx中为不同分辨率缩放ImageButtons? - How to use ViewPorts to scale ImageButtons for different resolutions in libgdx? 如何为不同的分辨率强制字体大小以px为单位 - How to force fonts to be same size in px for different resolutions 如何根据屏幕分辨率在libgdx中缩放精灵? - How to scale sprites in libgdx according to screen resolutions? 如何为不同的设备分辨率设置以下值? - how do i set the below values for different device resolutions? 布局JPopupMenu:如何为同一菜单中的菜单项提供不同的大小 - Layout JPopupMenu: How to provide different size for menu items in same menu 通过保持不同屏幕分辨率的宽高比来计算图像大小 - Image size calculation by keeping aspect ratio with different screen resolutions 暴露于不同的屏幕分辨率时动态更改JFrame的大小 - Dynamically changing the size of JFrame when exposed to different screen resolutions 如何调整具有不同分辨率的应用程序的所有控件的大小 - How to ReSize All Controls Of Application With Different Resolutions 如何在JavaFx中为不同的分辨率自动调整窗口大小? - How to automatically resize windows in JavaFx for different resolutions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM