JComboBox disappears when positioned over a JFreeChart in a JLayeredPane - java

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.

Related

How to align a JTextField that it is always on the far right side of the window?

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.

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!

How to view components outside the JFrame?

I have some JLabels which are not in view on the JFrame. My JFrame has the dimensions: 1366x by 750y. I want to put a few JLabels that are below these dimensions, i.e. at position 800y. It will be a JLabel which has the size 100x by 50y.
I want to have the label already declared and customised from the swing class. But I want to only add it to a scroll panel when I press a button. That way, the scroll panel will not scroll until you press the button. This is how it will work:
Panel scroll panel which doesn't scroll
Button is clicked
The label is added to the scroll panel
The scroll panel can now scroll. It will scroll because it is set to ASNEEDED for the verticalscrollbarpolicy.
The problem I have is that I can't see the label when it is under the JFrame in the design view of eclipse. Here is a photo:
How can I do this? Please ask for clarification if required.
EDIT
Now If I clicked on some other component above the currently selected label, the eclipse workbench area would scroll up and I wouldn't be able to scroll down to it. To find this label, I would have to find it in the Component Structures list on the left side. I want to be able to scroll the actual workbench area and I want to be able to see the text in that label which is circled.

How to create a rectangle with multiple images inside?

What is the best way to display let's say rectangle (3x5) with icons 20x20 px.? I want to change the image file of every pic icon later (= it's not just static pictures). I tried to make JFrame full of JPanels, but i was able to display only one panel at a time. I don't want to use GridLayout, because I need just small rectangle inside a frame. Any ideas how to do it? Couldn't find any tutorial or solution. I'm completely new to GUI developement. Thanks
You do want to use a GridLayout. Your problem is that the JFrame you put the icons into uses a BorderLayout by default (and really, you shouldn't change the layout of a top level component).
What this means is that, if you add multiple panels to the frame, without using one of the NORTH, EAST, SOUTH, WEST constraints, only one of the panels will be visible and take up all the space. If you use a GridLayout for that one panel you get, the icons will be stretched, because the panel receives all the space due to the frame's BorderLayout. An alternate layout that doesn't stretch its contents is FlowLayout, but the layout to use depends heavily on your context.
To display the icons, a JLabel is handy. Use an ImageIcon for the label's icon. You can later use setIcon() on the label to choose a new icon.
overall, my approach would be this:
use a JFrame which has a BorderLayout
to the frame, add a JPanel to the frame. The default layout is a FlowLayout, which will prevent the stretching
to the panel, add a JPanel with an appropriate GridLayout
to that panel, add the JLabels, each having an appropriate ImageIcon

Sliding hidden sections of a JPanel into view

I want to display a JFrame ( made with the Netbeans GUI Editor ) that has an enclosed panel ( the panel encovers the entire JFrame ). The panel is twice as wide as the frame, so I want it so that when a button is pressed inside of the panel, the panel's visible area slides over ( over about 2 seconds) to the hidden area of the JPanel and the previously visible section of the JPanel becomes invisible. I couldn't find any function how to set the currently visible section of a JPanel, so the function and/or a different solution to this would be helpful.
I suggest that you put the JPanel in a JScrollPane, one that if you wish does not show its scrollbars. Then you could easily use the scrollpane's model and a Swing Timer to create an animation that shows the JPanel sliding.
The solutions is CardLayout based http://java-sl.com/tip_slider.html
You can add 2 (or more) panels into container and rotate them.

Categories

Resources