How to handle oversized JDialog

岁酱吖の 提交于 2019-12-13 03:52:59

问题


I'm developing a JDialog which will have three sections, one on the top of the other: customer general information, list of customer addresses and list of orders.

The list of customer addresses may grow arbitrarily large and this causes the dialog to grow beyond the screen height.

Thus, calling pack() before displaying it does not work because the packed dialog height is still too big for the screen height.

This calls for a scroll pane. But I would have to set the dialog's preferred size to take advantage of it, and defining a size for it depends on the display resolution. I'm not sure how to do that.

How should I handle this scenario?


回答1:


First off, you can use Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); to get the screen size and then size the dialog proportionally (and place the content in a JScrollPane).

Second, I'd suggest adding some kind of collapse on items so you only see the ones you are actually interested in.



来源:https://stackoverflow.com/questions/55651192/how-to-handle-oversized-jdialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!