Before reading about my problem, first look at this GUI Diagram.
There are three bars at the top as follows:
one having buttons "pictorial view", "textual view" etc.
second having buttons "processes", "organisation" etc.
third having buttons "application to processes" etc.
After that two information bars are there.
After that a canvas window displaying the diagram.
Now, I want a GUI similar to this with the following features (relative to the above diagram):
At first, only first bar appears and below it a white blank canvas having no diagram appears spreading all over the GUI.
When the user clicks on the "pictorial view" button the second bar appears below the first bar and after that the same canvas without diagram spreading over the remaining space
When the user clicks on the "application" button on the second bar, the third bar appears below the second bar, and after that the same empty canvas spreading over the remaing space in the GUI.
I had tried to implement it by first having a "main panel" with BorderLayout. After that as showing in the following figure:
mainPanel(Border Layout)
|
|--topPanel (at NORTH of the mainPanel's Border Layout)
|
|
|--centerPanel (at CENTER of the mainPanel's Border Layout)
topPanel - to contain all the bars (bars should be added dynamically when a user clicks on a button)
centerPanel - to contain the canvas and adjust its size automatically when new bars are added in the topPanel
I would use a BorderLayout for the app, with the toolbars in a northerly pane.
That north pane I'd give a vertical BoxLayout and put the 3 toolbars into 3 successive boxes. That should take care of the geometry.
I'm not sure if making a toolbar invisible will cause it not to occupy space, but that would be the simplest. Alternatively, you could dynamically add()/remove() toolbars from the north pane.
The other alternative is to go with MigLayout where you can add as many components as you need to the "top". By setting "hidemode" parameter you can specify how space will occupied by invisible components.
In general MigLayout is much more flexible for almost any task and can be used instead of any standard layout or combination of layouts
Related
I'm wondering how I can add (what LayoutManager should I use) to make the app automatically adjust the components to the current size when full screen mode is enabled or even when the frame is stretched.
Currently this is what the application looks like, when you enable full screen mode the components are static.
UPDATE: I'm pasting pictures so you can get an idea of what I wrote.
Component layout in IntelliJ: layout
The current design in the small window looks ok: current design
Appearance if we enlarge the window (window zooms in, elements are static): full screen
So I'd like the components to automatically resize to the current window when fullscreen mode is enabled.
Okay. I suggest the following design:
your mainPanel, that you assigned as contentPane for your frame gets a Borderlayout.
In the North, you put a panel with a label or just a label, with Allignment X to the left.
the West gets a panel I suggest we call WestPanel and the East gets another one, which I call EastPanel.
WestPanel gets a Boxlayout or a Gridlayout. If you use Gridlayout, you can use 2 Grids wide and for each line one grid depth. You then can add all the labels in the left column and the textfields on the right.
Or you can make panels, with Borderlayout, labels to the West, textfields to the east, and pile them with emptyBorders ontop of each other. I suggest using a method for that.
The EastPabel gets a Tabbed Pane inside of it. Each tab can have its own layout manager, depending on what you want it to be in the end.
Does this help you?
I would like to create the main menu for my program and I have difficulties with Swing.
How would you code an alignment like this?
The middle elements would be the options like exit or settings and this window should be able to be resized and its contents should get bigger proportionally.
Single column GridLayout with vertical padding declared in the constructor. A grid layout will stretch components to fit the available space.
Add a large EmptyBorder to the JPanel that contains the 3 buttons, and that's the job done.
Problem is when i create GUI in jFrame window on screen and run the program later it in full screen using
setExtendedState(MAXIMIZED_BOTH);
it do not show up like it looked in that window see the red bordered area
Components appears in one corner of screen or only at a small part in center depending upon layouts and rest is empty space like this
I want JFrame window (see the red bordered area in first image) which is showed while creating GUI to represent my whole screen so that i can know how it will look when i run it in full screen.
Change the layout manager, may be using a combination of BorderLayout and GridBagLayout
These will provide you with a means to define how the components are positioned and sized within the parent container
See Layout out components within a container for more details
I have a UI requirement in java swing wherein I need to achieve the below:
The 2 buttons on the top are placed in a JPanel. I need to draw a line through the center of that panel, upto the beginning of the 2 buttons. The panel below is a container of panels arranged in a card layout. As and when the button is clicked, the card is switched showing another panel.
So in all respects this looks like a JTabbedPane, with one difference, the tabs are buttons arranged in the center of the tabbed pane. I need this difference for the UI I am building.
As of now, the buttons and card layout panel, looks like the below
As you can see, the buttons and panels appear and look separate, instead it would be nice if they are made to appear like they represent one unit.
As you can see, the buttons and panels appear and look separate, instead it would be nice if they are made to appear like they represent one unit.
Put the Border around the outer panel. That is use a panel with a BorderLayout. This panel can have a LineBorder. Then you add your button panel to the NORTH and the panel with the CardLayout to the CENTER.
The line won't be drawn through the buttons but the buttons and panel will appear like they represent on unit.
I have two JPanels that needs to add a JPanel into it, however only the last added JPanel does it show the JPanel. As shown below:
holderPanel1.add(dataPanel);
holderPanel2.add(dataPanel);
only holderPanel2 shows the dataPanel, but holderPanel1 does not show.
UI Components (such as JPanel) are the underline representation of things you see on the screen (location, parent, sub-components etc.), so each panel that you see on the screen has to have a separate underline representation, so you cannot add a panel to two different panels, you need to create two separate panels.