Luzifer-san
Luzifer-san

Reputation: 13

JLayeredPane disrupting Layout

I want to have a calendar with entries overlapping a JTable. That JTable is inside a scrollpane which again is inside a JLayeredPane.

setLayout(new MigLayout("", "[:20%:200px,grow][26%,grow][26%,grow][26%]", "[:15%:80px,grow][85%,grow]"));

add(layeredPane, "cell 1 1 3 1,grow");
layeredPane.setLayout(new MigLayout("", "[100%,grow]", "[100%,grow]"));
layeredPane.setBackground(Color.BLACK);

table = new JTable();

JScrollPane scrollPane = new JScrollPane(table);
layeredPane.add(scrollPane, "cell 0 0,grow",0);

I'm now calculating the bounds for my panel which is supposed to be an entry. When adding that entry to the JLayeredPane however, the whole layout is disrupted and it seems to be on the same layer. Even if my calculated values are wrong, that wrong result is still supposed to show up on a different layer.

JPanel panel = new JPanel();
panel.setBounds((int)position.getX(), (int)position.getY(), width, height);
panel.setBackground(Color.BLACK);
pane.add(panel, 300); // This is the JLayeredPane

When I go into fullscreen however, this happens:

enter image description here

Why is the pane not showing the panel on a different layer and why is my layout corrupted by it?

Upvotes: 0

Views: 108

Answers (1)

camickr
camickr

Reputation: 324147

pane.add(panel, 300); 

Well, that appears to be the code where you add your panel to the layered pane. Although elsewhere in your code you also have a variable called "layeredPane", so I'm not sure.

If that is referring to the layered pane then that is not how you add a component to the layer:

  1. why would you use 300 for the layer? that is not a pixel location
  2. The layer is specified by an Integer value, not an int.

Read the section from the Swing tutorial on How to Use Layered Panes for more information and a working example.

Upvotes: 1

Related Questions