• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java Swing Question

Crusty

Lifer
What is the easiet way to resize all my Components when my JFrame has been resized. Say for instance, the user hits the maximize button and the window maximizes.

I set up a listener for my JFrame getting resized and inside the function I attempt to resize the components I need to scale to the new size.

addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentResized(java.awt.event.ComponentEvent evt) {
formComponentResized(evt);
}
});


jSplitPaneMain.setSize((int)mainPanel.getSize().getWidth(),(int)mainPanel.getSize().getHeight()-100);

is my resize call...but it doesn't change the size of the JSplitPane...what am I doing wrong? Or is there an easier way to do this?
 
The easier way is to make the layout manager do most of the work for you. Example, if your component is set to be CENTER for a BorderLayout, it will automatically take up as much room as it can.

It may actually be your layout manager that's fiddling with the sizes already, which is why setSize doesn't do what you'd expect.

Since you're using a JSplitPane, this function is rather useful, since it let's you set a relative position for the divider location.

void setDividerLocation(double proportionalLocation)
Sets the divider location as a percentage of the JSplitPane's size.
 
Originally posted by: Kilrsat
The easier way is to make the layout manager do most of the work for you. Example, if your component is set to be CENTER for a BorderLayout, it will automatically take up as much room as it can.

It may actually be your layout manager that's fiddling with the sizes already, which is why setSize doesn't do what you'd expect.

Since you're using a JSplitPane, this function is rather useful, since it let's you set a relative position for the divider location.

void setDividerLocation(double proportionalLocation)
Sets the divider location as a percentage of the JSplitPane's size.

Hrmm, well here is how things are setup.

JFrame that has a JMenuBar, and a JTabbedPane. Now in one of my tabs there is JSplitPane that has a horizontal divider. On the top are a few options and whatnot, and on the bottom there is another JSplitPane that is split vertically with a Tree on the left and a Table on the right.

But I will mess with the layout manager and see if I can fix things up 🙂
 
Originally posted by: MCrusty
Originally posted by: Kilrsat
The easier way is to make the layout manager do most of the work for you. Example, if your component is set to be CENTER for a BorderLayout, it will automatically take up as much room as it can.

It may actually be your layout manager that's fiddling with the sizes already, which is why setSize doesn't do what you'd expect.

Since you're using a JSplitPane, this function is rather useful, since it let's you set a relative position for the divider location.

void setDividerLocation(double proportionalLocation)
Sets the divider location as a percentage of the JSplitPane's size.

Hrmm, well here is how things are setup.

JFrame that has a JMenuBar, and a JTabbedPane. Now in one of my tabs there is JSplitPane that has a horizontal divider. On the top are a few options and whatnot, and on the bottom there is another JSplitPane that is split vertically with a Tree on the left and a Table on the right.

But I will mess with the layout manager and see if I can fix things up 🙂
What component isn't resizing the way you expect?

I've worked with something similar before, only my JSplitPane was top and bottom instead of left and right. With no fiddling, the two panels expanded left/right as much as the window resized.

So if the behavior is similar, your components should expand up and down as much as they can already, and I bet if you simply reset the divider location, it'll do what you want.

 
Originally posted by: Kilrsat
Originally posted by: MCrusty
Originally posted by: Kilrsat
The easier way is to make the layout manager do most of the work for you. Example, if your component is set to be CENTER for a BorderLayout, it will automatically take up as much room as it can.

It may actually be your layout manager that's fiddling with the sizes already, which is why setSize doesn't do what you'd expect.

Since you're using a JSplitPane, this function is rather useful, since it let's you set a relative position for the divider location.

void setDividerLocation(double proportionalLocation)
Sets the divider location as a percentage of the JSplitPane's size.

Hrmm, well here is how things are setup.

JFrame that has a JMenuBar, and a JTabbedPane. Now in one of my tabs there is JSplitPane that has a horizontal divider. On the top are a few options and whatnot, and on the bottom there is another JSplitPane that is split vertically with a Tree on the left and a Table on the right.

But I will mess with the layout manager and see if I can fix things up 🙂
What component isn't resizing the way you expect?

I've worked with something similar before, only my JSplitPane was top and bottom instead of left and right. With no fiddling, the two panels expanded left/right as much as the window resized.

So if the behavior is similar, your components should expand up and down as much as they can already, and I bet if you simply reset the divider location, it'll do what you want.

Well, I was using Absolute Layout 😱. Once I set it to Border Layout the SplitPanes are resizing to fit the full screen 🙂

Thx for pointing that out.
 
Back
Top