intellij and swing - changing jpanel size
I am using intellij with swing.
My application runs on different computers with different monitors. I want to display my form in different sizes.I have a JPanel (not the main . inner jpanel ) set to (-1,670) in the intellij gui editor.
And I try to change it with this code : MyFormUI myform = new MyFormUI();
if (thisIsTheCase){
myform.setLongView()
}
and in MyFormUI ->
public void setLongView(){
myPanel.setPrefferedSize(new Dimension(-1, 1000))
myPanel.repaint() ;
revalidate();
// I tried also repaint and revalidate on a higher jpanel in th开发者_StackOverflow社区e hierarchy
}
When I change it in the gui editor - it does change, but not through code.
any suggestions?myPanel.setPrefferedSize(new Dimension(-1, 1000))
myPanel.repaint();
revalidate();
Not sure what the -1 does.
The code should be:
myPanel.revalidate();
myPanel.repaint();
The revalidate() actually redoes the layout of the component and the repaint just paints it. In your code you are repainting before redoing the layout.
Preferred size is, as you may guess, only preferred. If the underlying layout manager does not want to use this setting, it is free to discard it. IntelliJ IDEA is using its own layout manager, so you need to check if the panels Horizontal and Vertical size policies allow resizing.
It will be easier to diagnose the problem if you describe your layout in more details.
精彩评论