I am unable to make any components apear on a JLayeredPane when adding it to a JDialog.
I have also been unable to find a web resource that shows this may be done in a reasonably sized block of code. Every sight iv looked at “claims” this can be done, and then shows a disgustingly long solution.
What i want is to take a JLayered pane add a Button and place a JLabel with an icon in it onto this pane aswell. In english i want a button with an icon stuck in the front of its text.
That is the awt Button as I have been unable to find a way of making a system looking swing JButton.
Edit: could you help me out with something a little more specific. I think I was a littile to vague in my post.
Button button = new Button("ok");
JDialog dialog = new JDialog(null,"Windows",Dialog.ModalityType.APPLICATION_MODAL);
dialog.getLayeredPane().add(button);
dialog.pack();
dialog.setVisible(true);
I don’t seem to have any issues…
Remember,
JLayeredPaneDOES NOT have a layout manager. You become responsible for managing the size and position of the child components, that’s the point.Updated with new example
The layered pane of the
JRootPaneis responsible for (amongst other things) laying out the content pane and menu bar. It is also used (in some cases) to display things like popups.Have a read through How to Use Root Panes
Using this, means you are competing with components already on the screen.
Unless you have VERY good reason to be messing with this component, I would suggest you avoid it as 1- It’s possible to be changed in the future (the layer position of the components) and 2- It may interfere with other components used by the Swing API