I have layered pane in swing application and in that layered pane I am displaying another pane. I have used setBounds method of pane to display pane in right bottom corner of layered pane but when I maximise the application window the pane remain on its specified coordinates which spoils the look of application in maximise mode, I want it to change its location and remain in right bottom corner of layered pane irrespective of main frame size.
So is there a way to get size or coordintes of layerd pane and use that to keep child pane in layered pane's right bottom corner, even if we adjust size of main window child pane should always remain in right bottom corner of layered pane
"By default a layered pane has no layout manager," but you can use one of the standard Layout Managers or write your own.
Related
I have a normal content pane in Java (IDE: Eclipse) and a JTextField.
Now I want the text field to always be on the far right, even if the size of the window changes. Is this somehow possible?
One way to is nest panels with different layout manager.
The default layout manager of the content pane of the frame is a BorderLayout (unless Eclipse changes it, in which case you should set it back to a BorderLayout.
Then you can:
create a JPanel with a FlowLayout that is right aligned.
add the text field to this panel.
add this panel to the BorderLayout.PAGE_START of the content pane.
add you main panel containing other components to the BorderLayout.CENTER.
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.
I have a JPanel that has a JLayeredPane. The JLayeredPane has a JPanel which has a BoxLayout and holds a JFreeChart. The JLayeredPane also has a JComboBox; see image below.
The Graph object is added to the chartHolder at runtime.
When i run the app the comboBox display correctly. Once the graph object is added to the chartHolder the combobox stops rendering. Only the graph will display.
If I click in the area where the combo box should be, the dropdown and the combobox become visible. If I click the graph to dismiss the dropdown the combo box disappears again.
chartHolder --> DEFAULT_LAYER in the jLayeredPane
comboBox --> Pallette_Layer in the jLayeredPane.
Based on the ordering I have provided to the JLayeredPane, the combo box should always render above the graph.
What is the issue?
How to Use Layered Panes: Laying Out Components in a Layered Pane mentions that "By default, a layered pane has no layout manager." You'll have to verify that you're setting both the position and size of each component, as shown here using setBounds(). ChartPanel inherits a FlowLayout from the parent class, JPanel, by default; a surrounding chartHolder with BoxLayout may be superfluous.
I used the drag and drop interface to put the components where I want them to be, but when the window is resized they lose their relative position. I have attached a screen shot of my hierarchy and of two windows to show how the components lose their position.
Hierarchy
Fullscreen
If you want to use the AnchorPane to layout your components, you can set the Anchor Pane Constraints, like in the image below:
This way it doesn't matter if you resize the screen, the button will always stay 10px far from the AnchorPane's right border.
When you use the AnchorPane to place components on screen you are not going to have a relative positioning, You should use others containers to layout your application. Read more about how to use Layout Panes here: Using Layout Panes
You need to study how to use Layout Panes. Dragging and dropping components results in absolute positioning, which really bad practice.
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...