extends JDesktopPane implements Scrollable : JDesktopPane « Swing « Java Tutorial






import java.awt.Dimension;
import java.awt.Rectangle;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.Scrollable;

class ScrollDesktop extends JDesktopPane implements Scrollable {
  public Dimension getPreferredScrollableViewportSize() {
    return getPreferredSize();
  }

  public int getScrollableUnitIncrement(Rectangle r, int axis, int dir) {
    return 50;
  }

  public int getScrollableBlockIncrement(Rectangle r, int axis, int dir) {
    return 200;
  }

  public boolean getScrollableTracksViewportWidth() {
    return false;
  }

  public boolean getScrollableTracksViewportHeight() {
    return false;
  }
}

public class Main extends JFrame {
  public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JDesktopPane desk = new ScrollDesktop();
    desk.setPreferredSize(new Dimension(1000, 1000));
    getContentPane().add(new JScrollPane(desk), "Center");
    JInternalFrame f1 = new JInternalFrame("Frame 1");
    f1.getContentPane().add(new JLabel("This is frame f1"));
    f1.setResizable(true);
    f1.pack();
    f1.setVisible(true);
    desk.add(f1, new Integer(10));

    JInternalFrame f2 = new JInternalFrame("Frame 2");
    f2.getContentPane().add(new JLabel("Content for f2"));
    f2.setResizable(true);
    f2.pack();
    f2.setVisible(true);
    desk.add(f2, new Integer(20));

    JInternalFrame f3 = new JInternalFrame("Frame 3");
    f3.getContentPane().add(new JLabel("Content for f3"));
    f3.setResizable(true);
    f3.pack();
    f3.setVisible(true);
    desk.add(f3, new Integer(20));

    f3.toFront();
    try {
      f3.setSelected(true);
    } catch (java.beans.PropertyVetoException ignored) {
    }

    pack();
    setSize(300, 300);
    setVisible(true);
  }

  public static void main(String arg[]) {
    new Main();
  }
}








14.54.JDesktopPane
14.54.1.JDesktopPane is a specialized JLayeredPane.
14.54.2.Adding Internal Frames to a JDesktopPaneAdding Internal Frames to a JDesktopPane
14.54.3.JDesktopPane.PALETTE_LAYERJDesktopPane.PALETTE_LAYER
14.54.4.extends JDesktopPane implements Scrollable
14.54.5.Getting All Frames in a JDesktopPane Container
14.54.6.Creating a JDesktopPane Container
14.54.7.Create a virtual desktop in your application
14.54.8.Customizing a JDesktopPane Look and Feel