Resizing a frame and its components when using NULL Layout

孤人 提交于 2019-12-13 08:21:14

问题


When using null layout, how to resize components?

I mean their position and size. I know that using layout managers we need not take care of this issue. But my requirement is to move components in the panel. So I ought to use null layout.

Please let me know if you have ideas regarding finding new locations to place components on resize of the frame.


回答1:


Doing Without a Layout Manager tutorial may help, although it is recommended that you use a layout manager, if at all possible.

Recommendations

  1. Either use a layout manager, or
  2. Register a ComponentListener and manually resize/position components when a resize event occurs.

The labor incurred with the latter approach may be enormous, and hence why using a layout manager comes highly recommended. Another, albeit cheap alternative (which I'm sure violates your requirements), is to invoke setResizable(false) on your JFrame.




回答2:


for a component to be displayed in a null layout, they must of the bounds set on the component. They need a position(x,y) and a width/height



来源:https://stackoverflow.com/questions/6459001/resizing-a-frame-and-its-components-when-using-null-layout

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