问题描述
我有一个应用程序,希望用户可以在普通设置和高级设置之间进行选择.现在,如果用户检查了JCheckBox,并且高级设置应该消失,问题就开始了.我的想法是将所有不必要的摆动组件(JScrollPane,JLabel ...)设置为不可见,然后找到一种JFrame的方法使窗口适合可视组件.我的问题是是否有这种方法?
I have an application where I want that the user is able to choose between normal and advanced settings. Now if the user checks a JCheckBox and the advanced settings should disapper the problem starts.My idea was to set all unnessecary swing components (JScrollPane, JLabel...) invisible and then find a method of JFrame which fits the window to the VISIBLE components.My question is if there is such a method?
推荐答案
1..您可以使用setVisible(boolean b)
使该组件可见和不可见.
1. You can use setVisible(boolean b)
, to make the component visible and invisible.
2..您可以使用isVisible()
3..然后,您可以使用pack()方法, pack()方法根据需要设置帧大小
3. You can then use the pack() method, pack() method gives sets the frame size as per need
这篇关于JFrame调整大小以显示可见的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!