Swing vertical resizing one pane to expand other shrink (modified BorderLayout) - java

Basically i would like to have BorderLayout that will expand north section vertically and shrink center section on resize. I think it's easier to explain with pictures.
So here is situation I have now:
But when dialog is resized i would like to have buttons expand vertically and to shrink down center pane (one with tabs). Currently when dialog is resized i get this (the rest of the buttons are "hidden":
My current layout is set like this:
contentPane - BorderLayout
panelTopButtons - FlowLayout (set in north section of conentPane)
panelContent - BorderLayout (set in center section of contentPane)
So how can i achieve when dialog is resized that buttons in north section take more vertical space (and thus all are visible), and content of panelContent is shrink to fit rest of dialog contentPane space?

Put the buttons in the CENTER and the tabbed pane in the PAGE_END of the BorderLayout.

Related

Changing BorderLayout in Java Swing for more appealing UI

I would like to change my current layout to a new one, more advanced, but I have some issues with it. The current layout is as this:
All the displayed elements are in a panel (bottom panel, there is a top one which just includes JTable but is not relevant in this case) the checkboxes are in a JScrollPaneBox, which border layout is
BorderLayout.CENTER, then the buttons are in a Box and added to the panel with border layout BorderLayout.EAST, and the search field is added to the panel with borderlayout BorderLayout.SOUTH
But this layout is especially 'ugly' when the app is on fullscreen.
I would like to have a layout like this: https://wireframe.cc/Kb05km
How can I add the two labels and add a space between checkboxes and search field? Also how can I limit the maximum width of checkboxes' ScrollPaneBox and the search field?
Thanks!

Proportional Resizing using BorderLayout in Java

I am trying to create a GUI in which has three main panels for a text-based game: the leftmost panel for your stats/inventory, the center panel will be for a text pane that displays the story and a text field to type your commands, and the rightmost pane contains quest and mission information. I set the main content pane to have a BorderLayout and added JPanels to the west, center, and east positions (no components added to the panels yet). The center panel takes up most of the space, so I set the east's and west's panels' preferredSize width to be 200, which looks great proportionally for the size of the JFrame (800x500). When maximising the window, however, the east and west panels remain at 200 rather than scaling up proportionally, making it seem small compared to the center panel. When resizing the width of the window to be smaller than 800, the east and west panels remain 200 while the center panel gets smaller, to the point of the east and west panels overlapping. I was wondering if it would be possible to use BorderLayout's west, center, and east positions to scale proportionally upon resizing rather than just the center resizing up and down.
Thank you much for your time!
Edit:
Here are a couple snapshots to show the GUI. It is saying I do not have enough reputation to include images on my posts, so I can only include the hyperlinks to them.
The first image shows the frame at 800x500, the default size (blank space at left and right of the center panel are empty JPanels). The second image shows the GUI maximised (left and right panels remaining at 200).
scale proportionally upon resizing rather than just the center resizing up and down.
I suggest you to use GridBagLayout where you can set the width and height of the components in percentage defining different constraints of GridBagConstraints
See Swing Tutorial on How to Use GridBagLayout

Vertical scrolling of panel doesn't work java

So I'm making a program as a project for school.
In this program I have a panel inside a scrollpane.
When I click a button a panel with info is added to the panel inside the scrollpane.
I can keep adding as much of these panels as I want.
I set the layout of the panel to FlowLayout.
I disabled the horizontal scrolling and set the width of the panel to the width of the scrollpane so I neatly get two of those 'forms' next to each other before it starts a new row of panels.
Problem is the vertical scrolling doesn't activate so I can see only 1,5 rows of panels. (see picture)
http://i1281.photobucket.com/albums/a518/Bas_Van_den_Steen/Screenshot2014-05-22191813_zps44483b9b.png
I suspect this has something to do with the height of the main panel I had to define if I wanted to set a width.
Ideally there should be an option to set the height to 'automatic', but there isn't.
I know scrolling works because when I enable horizontal scrolling and don't set any dimensions for the panel it just keeps adding forms in a single row which I can scroll through.
I think I might need to use another LayoutManager (but I don't have any experience setting those up) or change some of the settings of the scrollpane or main panel.
Can someone help me with this?
I set the width of the panel to the width of the scrollpane so I neatly get two of those 'forms' next to each other before it starts a new row of panels. Problem is the vertical scrolling doesn't activate
A FlowLayout is designed to display components horizontally and the preferred size is always based on a single row of components.
Use a different layout manager. Maybe a vertical BoxLayout, or GridBagLayout or GridLayout depending on your exact requirement.
Read the section from the Swing tutorial on Using Layout Managers for more information and working examples.
set the width of the panel to the width of the scrollpane
You should not be manually setting the preferred width of you panel. As I mentioned earlier that is the job of the layout manager. Maybe the GridLayout is closes to what you need.

gwt scroll pane that takes it size from the other components

I have a screen in gwt where a portion of the screen has a scroll panel. There is a header bar at the top and the rest of the screen is in a scroll panel.
Problem is I can only get the scroll bars to appear if I set the absolute height of the scroll panel. The content in the scroll panel is bigger than the scroll panel but the scroll bars don't appear unless I specify the size of the scroll panel absolutely. The problem with this is it does not take into account the size of the browser window...
Thanks, this answer helped me gwt-layoutpanel-size.
Basically, the bottom line is that if you want the scroll panel to resize and maintain the scroll bars all your parent containers must implement RequiresResize so that the scroll panel can listen for the event and act accordingly.
Your flexibility is severely limited when requiring this behaviour as you can only put the scroll panel inside elements that implement RequiresResize/Provides Resize which are the *LayoutPanels...

Which Java text component should I be using to get it to resize to fit the frame as it is resized?

I have a JTabbedPane and a JTextArea, I want the Textareas/Panes to resize to fit the window when the window is resized. How do I do this? I'm also fuzzy on if it's the right text component to use.
Really Muddled.
EDIT: I was setting explicit size as a dumb dumb. I've got it all worked out. What I did is set the viewport of a JScrollPane as the JTextArea and remove all explicit sizing.
Thanks chaps!
You can use whatever components you like. All JComponents can resize with a resizing parent container. You simply need to choose the correct LayoutManager.
Depending on how you want everything set up, I assume you will want to add your JTabbedPane to your JFrame like so:
JTabbedPane jtp;
JFrame frame;
// JFrame's default layour is border layout.
frame.add(jtp, BorderLayout.CENTER);
This will cause the JTabbed pane to take up all of the space of the JFrame.
You will also need to set your JTabbedPane's layout manager to BorderLayout, and also any tab you add to the JTabbedPane will need to have a BorderLayout.
To set the layout of your components, do:
JComponent anyComponent;
anyComponent.setLayout(new BorderLayout());
Have a look at the Java LayoutManager tutorials for more information.
I should mention that the reason I suggest BorderLayout is because any component added to the CENTER of a BorderLayout will automatically take up any space not taken up by any of the borders. And, since you aren't adding anything to any of the other borders (NORTH, SOUTH, EAST, WEST) the component in the center will take up the entire space.
Every JComponent is resized automatically when the container it resides in, is resized.
It's not a matter of the right component but more a matter of which LayoutManager to use.
When adding a Component to a container, you can set the minimum size, default size and maximum size.
On resizing the container, the component will scale automatically until reaching the desired maximum size.
If you need code snippets, tell me and I will fire up my IDE later.
cheers
EDIT: jjnguy beat me to it.. nvm then :p

Categories

Resources