Example usage for javax.swing JDesktopPane JDesktopPane

List of usage examples for javax.swing JDesktopPane JDesktopPane

Introduction

In this page you can find the example usage for javax.swing JDesktopPane JDesktopPane.

Prototype

public JDesktopPane() 

Source Link

Document

Creates a new JDesktopPane.

Usage

From source file:SampleDesktop.java

public SampleDesktop(String title) {
    super(title);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    // Create a desktop and set it as the content pane. Don't set the
    // layered//from www .ja  va 2  s.  c o m
    // pane, since it needs to hold the menu bar too.
    desk = new JDesktopPane();
    setContentPane(desk);

    // Install our custom desktop manager.
    desk.setDesktopManager(new SampleDesktopMgr());

    createMenuBar();
    loadBackgroundImage();
}

From source file:OptPaneComparison.java

public OptPaneComparison(final String message) {
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    final int msgType = JOptionPane.QUESTION_MESSAGE;
    final int optType = JOptionPane.OK_CANCEL_OPTION;
    final String title = message;

    setSize(350, 200);// w  ww .  j  a v a 2 s  .c o  m

    // Create a desktop for internal frames
    final JDesktopPane desk = new JDesktopPane();
    setContentPane(desk);

    // Add a simple menu bar
    JMenuBar mb = new JMenuBar();
    setJMenuBar(mb);

    JMenu menu = new JMenu("Dialog");
    JMenu imenu = new JMenu("Internal");
    mb.add(menu);
    mb.add(imenu);
    final JMenuItem construct = new JMenuItem("Constructor");
    final JMenuItem stat = new JMenuItem("Static Method");
    final JMenuItem iconstruct = new JMenuItem("Constructor");
    final JMenuItem istat = new JMenuItem("Static Method");
    menu.add(construct);
    menu.add(stat);
    imenu.add(iconstruct);
    imenu.add(istat);

    // Create our JOptionPane. We're asking for input, so we call
    // setWantsInput.
    // Note that we cannot specify this via constructor parameters.
    optPane = new JOptionPane(message, msgType, optType);
    optPane.setWantsInput(true);

    // Add a listener for each menu item that will display the appropriate
    // dialog/internal frame
    construct.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {

            // Create and display the dialog
            JDialog d = optPane.createDialog(desk, title);
            d.setVisible(true);

            respond(getOptionPaneValue());
        }
    });

    stat.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            String s = JOptionPane.showInputDialog(desk, message, title, msgType);
            respond(s);
        }
    });

    iconstruct.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {

            // Create and display the dialog
            JInternalFrame f = optPane.createInternalFrame(desk, title);
            f.setVisible(true);

            // Listen for the frame to close before getting the value from
            // it.
            f.addPropertyChangeListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent ev) {
                    if ((ev.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY))
                            && (ev.getNewValue() == Boolean.TRUE)) {
                        respond(getOptionPaneValue());
                    }
                }
            });
        }
    });

    istat.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            String s = JOptionPane.showInternalInputDialog(desk, message, title, msgType);
            respond(s);
        }
    });
}

From source file:Main.java

public Main() {
    super("Focus Example");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    MyPanel mypanel = new MyPanel();

    JButton button1 = new JButton("One");
    JButton button2 = new JButton("Two");
    JButton button3 = new JButton("Three");
    JButton button4 = new JButton("Four");
    JButton button5 = new MyButton("Five*");
    JButton button6 = new MyButton("Six*");
    JButton button7 = new JButton("Seven");

    mypanel.add(button2);/*from ww  w .j av a 2s  .c o  m*/
    mypanel.add(button3);

    JInternalFrame frame1 = new JInternalFrame("Internal Frame 1", true, true, true, true);

    frame1.setBackground(Color.lightGray);
    frame1.getContentPane().setLayout(new GridLayout(2, 3));
    frame1.setSize(300, 200);

    frame1.getContentPane().add(button1);
    frame1.getContentPane().add(mypanel);
    frame1.getContentPane().add(button4);
    frame1.getContentPane().add(button5);
    frame1.getContentPane().add(button6);
    frame1.getContentPane().add(button7);

    JDesktopPane desktop = new JDesktopPane();
    desktop.add(frame1, new Integer(1));
    desktop.setOpaque(true);

    // Now set up the user interface window.
    Container contentPane = getContentPane();
    contentPane.add(desktop, BorderLayout.CENTER);
    setSize(new Dimension(400, 300));
    frame1.setVisible(true);
    setVisible(true);
}

From source file:MainClass.java

public MainClass() {
    super("Focus Example");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    MyPanel mypanel = new MyPanel();

    JButton button1 = new JButton("One");
    JButton button2 = new JButton("Two");
    JButton button3 = new JButton("Three");
    JButton button4 = new JButton("Four");
    JButton button5 = new MyButton("Five*");
    JButton button6 = new MyButton("Six*");
    JButton button7 = new JButton("Seven");

    mypanel.add(button2);/* w  ww  .j a v a 2s  . c om*/
    mypanel.add(button3);

    JInternalFrame frame1 = new JInternalFrame("Internal Frame 1", true, true, true, true);

    frame1.setBackground(Color.lightGray);
    frame1.getContentPane().setLayout(new GridLayout(2, 3));
    frame1.setSize(300, 200);

    frame1.getContentPane().add(button1);
    frame1.getContentPane().add(mypanel);
    frame1.getContentPane().add(button4);
    frame1.getContentPane().add(button5);
    frame1.getContentPane().add(button6);
    frame1.getContentPane().add(button7);

    JDesktopPane desktop = new JDesktopPane();
    desktop.add(frame1, new Integer(1));
    desktop.setOpaque(true);

    // Now set up the user interface window.
    Container contentPane = getContentPane();
    contentPane.add(desktop, BorderLayout.CENTER);
    setSize(new Dimension(400, 300));
    frame1.setVisible(true);
    setVisible(true);
}

From source file:FocusExample.java

public FocusExample() {

    super("Focus Example");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    MyPanel mypanel = new MyPanel();

    JButton button1 = new JButton("One");
    JButton button2 = new JButton("Two");
    JButton button3 = new JButton("Three");
    JButton button4 = new JButton("Four");
    JButton button5 = new MyButton("Five*");
    JButton button6 = new MyButton("Six*");
    JButton button7 = new JButton("Seven");

    mypanel.add(button2);//  ww w .  j  a  va 2  s . c  o  m
    mypanel.add(button3);

    JInternalFrame frame1 = new JInternalFrame("Internal Frame 1", true, true, true, true);

    frame1.setBackground(Color.lightGray);
    frame1.getContentPane().setLayout(new GridLayout(2, 3));
    frame1.setSize(300, 200);

    frame1.getContentPane().add(button1);
    frame1.getContentPane().add(mypanel);
    frame1.getContentPane().add(button4);
    frame1.getContentPane().add(button5);
    frame1.getContentPane().add(button6);
    frame1.getContentPane().add(button7);

    JDesktopPane desktop = new JDesktopPane();
    desktop.add(frame1, new Integer(1));
    desktop.setOpaque(true);

    //  Now set up the user interface window.
    Container contentPane = getContentPane();
    contentPane.add(desktop, BorderLayout.CENTER);
    setSize(new Dimension(400, 300));
    frame1.setVisible(true);
    setVisible(true);
}

From source file:SimpleInternalFrameDemo.java

public SimpleInternalFrameDemo() {
    super("Internal Frame Demo");
    setSize(500, 400);//from   w ww.ja  va  2 s  .c  om
    openButton = new JButton("Open");
    macButton = new JButton("Mac");
    javaButton = new JButton("Metal");
    motifButton = new JButton("Motif");
    winButton = new JButton("Windows");
    Panel p = new Panel();
    p.add(openButton);
    p.add(macButton);
    p.add(javaButton);
    p.add(motifButton);
    p.add(winButton);
    add(p, BorderLayout.SOUTH);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    openButton.addActionListener(new OpenListener());
    LnFListener lnf = new LnFListener(this);
    macButton.addActionListener(lnf);
    javaButton.addActionListener(lnf);
    motifButton.addActionListener(lnf);
    winButton.addActionListener(lnf);

    // Set up the layered pane
    desktop = new JDesktopPane();
    desktop.setOpaque(true);
    add(desktop, BorderLayout.CENTER);
}

From source file:JavaXWin.java

public JavaXWin() {
    setTitle("JavaXWin");
    m_count = m_tencount = 0;/*from  w ww.ja  va2s. co m*/
    m_desktop = new JDesktopPane();

    JScrollPane scroller = new JScrollPane();
    m_wm = new WindowManager(m_desktop);
    m_desktop.setDesktopManager(m_wm);
    m_desktop.add(m_wm.getWindowWatcher(), JLayeredPane.PALETTE_LAYER);
    m_wm.getWindowWatcher().setBounds(555, 5, 200, 150);

    viewport = new JViewport() {
        public void setViewPosition(Point p) {
            super.setViewPosition(p);
            m_wm.getWindowWatcher().setLocation(m_wm.getWindowWatcher().getX() + (getViewPosition().x - m_wmX),
                    m_wm.getWindowWatcher().getY() + (getViewPosition().y - m_wmY));
            m_wmX = getViewPosition().x;
            m_wmY = getViewPosition().y;
        }
    };
    viewport.setView(m_desktop);
    scroller.setViewport(viewport);

    ComponentAdapter ca = new ComponentAdapter() {
        JViewport view = viewport;

        public void componentResized(ComponentEvent e) {
            m_wm.getWindowWatcher().setLocation(
                    view.getViewPosition().x + view.getWidth() - m_wm.getWindowWatcher().getWidth() - 15,
                    view.getViewPosition().y + 5);
        }
    };
    viewport.addComponentListener(ca);

    m_newFrame = new JButton("New Frame");
    m_newFrame.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            newFrame();
        }
    });

    JPanel topPanel = new JPanel(true);
    topPanel.setLayout(new FlowLayout());

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add("North", topPanel);
    getContentPane().add("Center", scroller);

    topPanel.add(m_newFrame);

    Dimension dim = getToolkit().getScreenSize();
    setSize(800, 600);
    setLocation(dim.width / 2 - getWidth() / 2, dim.height / 2 - getHeight() / 2);
    m_desktop.setPreferredSize(new Dimension(1600, 1200));
    setVisible(true);
    WindowListener l = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(l);
}

From source file:InternalFrameListenerDemo.java

public InternalFrameListenerDemo() {
    setTitle("Animated InternalFrameListener");
    m_count = m_tencount = 0;//  www  .  j  av  a  2s.  co  m

    JPanel innerListenerPanel = new JPanel(new GridLayout(7, 1));
    JPanel listenerPanel = new JPanel(new BorderLayout());
    m_ifEventCanvas = new IFEventCanvas();

    m_lOpened = new JLabel("internalFrameOpened");
    m_lClosing = new JLabel("internalFrameClosing");
    m_lClosed = new JLabel("internalFrameClosed");
    m_lIconified = new JLabel("internalFrameIconified");
    m_lDeiconified = new JLabel("internalFrameDeiconified");
    m_lActivated = new JLabel("internalFrameActivated");
    m_lDeactivated = new JLabel("internalFrameDeactivated");

    innerListenerPanel.add(m_lOpened);
    innerListenerPanel.add(m_lClosing);
    innerListenerPanel.add(m_lClosed);
    innerListenerPanel.add(m_lIconified);
    innerListenerPanel.add(m_lDeiconified);
    innerListenerPanel.add(m_lActivated);
    innerListenerPanel.add(m_lDeactivated);

    listenerPanel.add("Center", m_ifEventCanvas);
    listenerPanel.add("West", innerListenerPanel);
    listenerPanel.setOpaque(true);
    listenerPanel.setBackground(Color.white);

    m_desktop = new JDesktopPane();
    m_desktop.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));
    m_newFrame = new JButton("New Frame");
    m_newFrame.addActionListener(this);
    m_infos = UIManager.getInstalledLookAndFeels();
    String[] LAFNames = new String[m_infos.length];
    for (int i = 0; i < m_infos.length; i++) {
        LAFNames[i] = m_infos[i].getName();
    }
    m_UIBox = new JComboBox(LAFNames);
    m_UIBox.addActionListener(this);
    JPanel topPanel = new JPanel(true);
    topPanel.setLayout(new FlowLayout());
    topPanel.setBorder(new CompoundBorder(new SoftBevelBorder(BevelBorder.LOWERED),
            new CompoundBorder(new EmptyBorder(2, 2, 2, 2), new SoftBevelBorder(BevelBorder.RAISED))));
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add("North", topPanel);
    getContentPane().add("Center", m_desktop);
    getContentPane().add("South", listenerPanel);
    ((JPanel) getContentPane()).setBorder(new CompoundBorder(new SoftBevelBorder(BevelBorder.LOWERED),
            new CompoundBorder(new EmptyBorder(1, 1, 1, 1), new SoftBevelBorder(BevelBorder.RAISED))));
    topPanel.add(m_newFrame);
    topPanel.add(new JLabel("Look & Feel:", SwingConstants.RIGHT));
    topPanel.add(m_UIBox);
    setSize(645, 500);
    Dimension dim = getToolkit().getScreenSize();
    setLocation(dim.width / 2 - getWidth() / 2, dim.height / 2 - getHeight() / 2);
    setVisible(true);
    WindowListener l = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(l);
    m_eventTimer = new Timer(1000, this);
    m_eventTimer.setRepeats(true);
    m_eventTimer.start();
}

From source file:InternalFrameTest.java

public DesktopFrame() {
    setTitle("InternalFrameTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    desktop = new JDesktopPane();
    add(desktop, BorderLayout.CENTER);

    // set up menus

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);/* w ww .  ja  v  a 2  s  . c om*/
    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);
    JMenuItem openItem = new JMenuItem("New");
    openItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            createInternalFrame(new JLabel(new ImageIcon(planets[counter] + ".gif")), planets[counter]);
            counter = (counter + 1) % planets.length;
        }
    });
    fileMenu.add(openItem);
    JMenuItem exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });
    fileMenu.add(exitItem);
    JMenu windowMenu = new JMenu("Window");
    menuBar.add(windowMenu);
    JMenuItem nextItem = new JMenuItem("Next");
    nextItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            selectNextWindow();
        }
    });
    windowMenu.add(nextItem);
    JMenuItem cascadeItem = new JMenuItem("Cascade");
    cascadeItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            cascadeWindows();
        }
    });
    windowMenu.add(cascadeItem);
    JMenuItem tileItem = new JMenuItem("Tile");
    tileItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            tileWindows();
        }
    });
    windowMenu.add(tileItem);
    final JCheckBoxMenuItem dragOutlineItem = new JCheckBoxMenuItem("Drag Outline");
    dragOutlineItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            desktop.setDragMode(dragOutlineItem.isSelected() ? JDesktopPane.OUTLINE_DRAG_MODE
                    : JDesktopPane.LIVE_DRAG_MODE);
        }
    });
    windowMenu.add(dragOutlineItem);
}

From source file:components.InternalFrameDemo.java

public InternalFrameDemo() {
    super("InternalFrameDemo");

    //Make the big window be indented 50 pixels from each edge
    //of the screen.
    int inset = 50;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset * 2);

    //Set up the GUI.
    desktop = new JDesktopPane(); //a specialized layered pane
    createFrame(); //create first "window"
    setContentPane(desktop);/*from  w w  w  .  ja  v  a2  s  .  c  om*/
    setJMenuBar(createMenuBar());

    //Make dragging a little faster but perhaps uglier.
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
}