File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Can I Use JLayeredPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Can I Use JLayeredPane" Watch "Can I Use JLayeredPane" New topic

Can I Use JLayeredPane

nabi bux
Ranch Hand

Joined: Mar 14, 2005
Posts: 73
To all I have the following Prpgram In which I Have Declayred Box and The JPanel I added Box To JPanel And Panel to JFrame content Please Compile the Following and Then sugget Me I Want to JInternal frame at right to the Frame what Should I do should I add JLayere pant To JFrame contentpane at right and then add Internal frame to it please Help here is the code

* @(#)
* DataBase application
* @author
* @version 1.00 2007/4/2

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.border.*;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JLayeredPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.*;
import java.awt.*;
public class DataBase extends JFrame {/*getContentPane().setLayout(
new BoxLayout( getContentPane(), BoxLayout.Y_AXIS );
. . . . .*/

JButton openButton, macButton, javaButton, motifButton, winButton;

JLayeredPane desktop;

JInternalFrame internalFrame;

public DataBase() {
super("Internal Frame Demo");
try {
} catch (Exception ex1) {
System.err.println("Unsupported LookAndFeel: " );
openButton = new JButton("Open");
macButton = new JButton("Mac");
javaButton = new JButton("Metal");
motifButton = new JButton("Motif");
winButton = new JButton("Windows");
setSize(500, 400);

JPanel p = new JPanel(new BorderLayout());
Box left=Box.createVerticalBox();
p.setBorder( new TitledBorder( new EtchedBorder(),"Function Buttton"));
Dimension size=new Dimension(100,20);

// b2.setMaximumSize(b3.getPreferredSize());
macButton.setMaximumSize(winButton.getPreferredSize());// Setting he size of Button With respect to Larger Button

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {

this.getContentPane().add(p, BorderLayout.WEST);


public static void main(String args[]) {
DataBase sif = new DataBase();
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 45345
Please use code tags for code quotes.
You can't simply put a JInternalFrame on top of a JPanel; JInternalFrames live inside JDesktopPanes. See this part of the Java Tutorial.
And rather than using your WindowListener, simply set the default closing operation to EXIT_ON_CLOSE. Details in the JFrame page of the API.
nabi bux
Ranch Hand

Joined: Mar 14, 2005
Posts: 73
OK thank to solve my problem
I agree. Here's the link:
subject: Can I Use JLayeredPane
It's not a secret anymore!