Example usage for javax.swing JDesktopPane getSize

List of usage examples for javax.swing JDesktopPane getSize

Introduction

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

Prototype

public Dimension getSize() 

Source Link

Document

Returns the size of this component in the form of a Dimension object.

Usage

From source file:SampleDesktop.java

public void dragFrame(JComponent f, int x, int y) {
    if (f instanceof JInternalFrame) { // Deal only w/internal frames
        JInternalFrame frame = (JInternalFrame) f;
        JDesktopPane desk = frame.getDesktopPane();
        Dimension d = desk.getSize();

        // Nothing all that fancy below, just figuring out how to adjust
        // to keep the frame on the desktop.
        if (x < 0) { // too far left?
            x = 0; // flush against the left side
        } else {// ww  w  . j  a va  2s . co m
            if (x + frame.getWidth() > d.width) { // too far right?
                x = d.width - frame.getWidth(); // flush against right side
            }
        }
        if (y < 0) { // too high?
            y = 0; // flush against the top
        } else {
            if (y + frame.getHeight() > d.height) { // too low?
                y = d.height - frame.getHeight(); // flush against the
                // bottom
            }
        }
    }

    // Pass along the (possibly cropped) values to the normal drag handler.
    super.dragFrame(f, x, y);
}

From source file:DialogDesktop.java

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

    final JDesktopPane desk = new JDesktopPane();
    setContentPane(desk);//from   w w  w .ja  va2 s  .c  o m

    // Create our "real" application container; use any layout manager we
    // want.
    final JPanel p = new JPanel(new GridBagLayout());

    // Listen for desktop resize events so we can resize p. This will ensure
    // that
    // our container always fills the entire desktop.
    desk.addComponentListener(new ComponentAdapter() {
        public void componentResized(ComponentEvent ev) {
            Dimension deskSize = desk.getSize();
            p.setBounds(0, 0, deskSize.width, deskSize.height);
            p.validate();
        }
    });

    // Add our application panel to the desktop. Any layer below the
    // MODAL_LAYER
    // (where the dialogs will appear) is fine. We'll just use the default
    // in
    // this example.
    desk.add(p);

    // Fill out our app with a few buttons that create dialogs
    JButton input = new JButton("Input");
    JButton confirm = new JButton("Confirm");
    JButton message = new JButton("Message");
    p.add(input);
    p.add(confirm);
    p.add(message);

    input.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            JOptionPane.showInternalInputDialog(desk, "Enter Name");
        }
    });

    confirm.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            JOptionPane.showInternalConfirmDialog(desk, "Is this OK?");
        }
    });

    message.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            JOptionPane.showInternalMessageDialog(desk, "The End");
        }
    });
}