下面列出了怎么用javax.swing.JDesktopPane的API类实例代码及写法,或者点击链接到github查看源代码。
public Test6505027(JFrame main) {
Container container = main;
if (INTERNAL) {
JInternalFrame frame = new JInternalFrame();
frame.setBounds(OFFSET, OFFSET, WIDTH, HEIGHT);
frame.setVisible(true);
JDesktopPane desktop = new JDesktopPane();
desktop.add(frame, new Integer(1));
container.add(desktop);
container = frame;
}
if (TERMINATE) {
this.table.putClientProperty(KEY, Boolean.TRUE);
}
TableColumn column = this.table.getColumn(COLUMNS[1]);
column.setCellEditor(new DefaultCellEditor(new JComboBox(ITEMS)));
container.add(BorderLayout.NORTH, new JTextField());
container.add(BorderLayout.CENTER, new JScrollPane(this.table));
}
private static void createAndShowGUI() {
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
desktopPane = new JDesktopPane();
desktopPane.setBackground(BACKGROUND_COLOR);
frame.add(desktopPane, BorderLayout.CENTER);
frame.setSize(FRAME_SIZE, FRAME_SIZE);
frame.setVisible(true);
internalFrame = new JInternalFrame("Test");
internalFrame.setSize(FRAME_SIZE / 2, FRAME_SIZE / 2);
desktopPane.add(internalFrame);
internalFrame.setVisible(true);
internalFrame.setResizable(true);
frame.setVisible(true);
}
public Test6505027(JFrame main) {
Container container = main;
if (INTERNAL) {
JInternalFrame frame = new JInternalFrame();
frame.setBounds(OFFSET, OFFSET, WIDTH, HEIGHT);
frame.setVisible(true);
JDesktopPane desktop = new JDesktopPane();
desktop.add(frame, new Integer(1));
container.add(desktop);
container = frame;
}
if (TERMINATE) {
this.table.putClientProperty(KEY, Boolean.TRUE);
}
TableColumn column = this.table.getColumn(COLUMNS[1]);
column.setCellEditor(new DefaultCellEditor(new JComboBox(ITEMS)));
container.add(BorderLayout.NORTH, new JTextField());
container.add(BorderLayout.CENTER, new JScrollPane(this.table));
}
static ComponentBuilder getBuilder(Instance instance, Heap heap) {
if (DetailsUtils.isSubclassOf(instance, JRootPane.class.getName())) {
return new JRootPaneBuilder(instance, heap);
} else if (DetailsUtils.isSubclassOf(instance, JDesktopPane.class.getName())) {
return new JDesktopPaneBuilder(instance, heap);
} else if (DetailsUtils.isSubclassOf(instance, JLayeredPane.class.getName())) {
return new JLayeredPaneBuilder(instance, heap);
} else if (DetailsUtils.isSubclassOf(instance, Frame.class.getName())) {
return new FrameBuilder(instance, heap);
} else if (DetailsUtils.isSubclassOf(instance, Dialog.class.getName())) {
return new DialogBuilder(instance, heap);
} else if (DetailsUtils.isSubclassOf(instance, JInternalFrame.class.getName())) {
return new JInternalFrameBuilder(instance, heap);
}
return null;
}
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);
setJMenuBar(createMenuBar());
// Make dragging a little faster but perhaps uglier.
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
}
static ComponentBuilder getBuilder(Instance instance, Heap heap) {
if (DetailsUtils.isSubclassOf(instance, JRootPane.class.getName())) {
return new JRootPaneBuilder(instance, heap);
} else if (DetailsUtils.isSubclassOf(instance, JDesktopPane.class.getName())) {
return new JDesktopPaneBuilder(instance, heap);
} else if (DetailsUtils.isSubclassOf(instance, JLayeredPane.class.getName())) {
return new JLayeredPaneBuilder(instance, heap);
} else if (DetailsUtils.isSubclassOf(instance, Frame.class.getName())) {
return new FrameBuilder(instance, heap);
} else if (DetailsUtils.isSubclassOf(instance, Dialog.class.getName())) {
return new DialogBuilder(instance, heap);
} else if (DetailsUtils.isSubclassOf(instance, JInternalFrame.class.getName())) {
return new JInternalFrameBuilder(instance, heap);
}
return null;
}
public Test6505027(JFrame main) {
Container container = main;
if (INTERNAL) {
JInternalFrame frame = new JInternalFrame();
frame.setBounds(OFFSET, OFFSET, WIDTH, HEIGHT);
frame.setVisible(true);
JDesktopPane desktop = new JDesktopPane();
desktop.add(frame, new Integer(1));
container.add(desktop);
container = frame;
}
if (TERMINATE) {
this.table.putClientProperty(KEY, Boolean.TRUE);
}
TableColumn column = this.table.getColumn(COLUMNS[1]);
column.setCellEditor(new DefaultCellEditor(new JComboBox(ITEMS)));
container.add(BorderLayout.NORTH, new JTextField());
container.add(BorderLayout.CENTER, new JScrollPane(this.table));
}
void adjustSize() {
JDesktopPane desktop = (JDesktopPane) getParent();
if (desktop != null) {
int height = getPreferredSize().height;
Insets insets = getInsets();
if (height == insets.top + insets.bottom) {
if (getHeight() <= height) {
// Initial size, because we have no buttons yet
height += 21;
} else {
// We already have a good height
height = getHeight();
}
}
setBounds(0, desktop.getHeight() - height, desktop.getWidth(), height);
revalidate();
repaint();
}
}
public Test6505027(JFrame main) {
Container container = main;
if (INTERNAL) {
JInternalFrame frame = new JInternalFrame();
frame.setBounds(OFFSET, OFFSET, WIDTH, HEIGHT);
frame.setVisible(true);
JDesktopPane desktop = new JDesktopPane();
desktop.add(frame, new Integer(1));
container.add(desktop);
container = frame;
}
if (TERMINATE) {
this.table.putClientProperty(KEY, Boolean.TRUE);
}
TableColumn column = this.table.getColumn(COLUMNS[1]);
column.setCellEditor(new DefaultCellEditor(new JComboBox(ITEMS)));
container.add(BorderLayout.NORTH, new JTextField());
container.add(BorderLayout.CENTER, new JScrollPane(this.table));
}
/**
* Creates the content for the application frame.
*
* @return a panel containing the basic user interface.
*/
private JDesktopPane init(final DemoController ctrl)
{
final JPanel content = new JPanel(new BorderLayout());
content.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
content.add(createDefaultTable(data));
content.add(new JButton(ctrl.getExportAction()), BorderLayout.SOUTH);
final JInternalFrame frame = new JInternalFrame();
frame.setClosable(false);
frame.setVisible(true);
frame.setContentPane(content);
frame.pack();
final JDesktopPane desktop = new JDesktopPane();
desktop.setDoubleBuffered(false);
desktop.add(frame);
return desktop;
}
public Test6505027(JFrame main) {
Container container = main;
if (INTERNAL) {
JInternalFrame frame = new JInternalFrame();
frame.setBounds(OFFSET, OFFSET, WIDTH, HEIGHT);
frame.setVisible(true);
JDesktopPane desktop = new JDesktopPane();
desktop.add(frame, new Integer(1));
container.add(desktop);
container = frame;
}
if (TERMINATE) {
this.table.putClientProperty(KEY, Boolean.TRUE);
}
TableColumn column = this.table.getColumn(COLUMNS[1]);
column.setCellEditor(new DefaultCellEditor(new JComboBox(ITEMS)));
container.add(BorderLayout.NORTH, new JTextField());
container.add(BorderLayout.CENTER, new JScrollPane(this.table));
}
public Test6505027(JFrame main) {
Container container = main;
if (INTERNAL) {
JInternalFrame frame = new JInternalFrame();
frame.setBounds(OFFSET, OFFSET, WIDTH, HEIGHT);
frame.setVisible(true);
JDesktopPane desktop = new JDesktopPane();
desktop.add(frame, new Integer(1));
container.add(desktop);
container = frame;
}
if (TERMINATE) {
this.table.putClientProperty(KEY, Boolean.TRUE);
}
TableColumn column = this.table.getColumn(COLUMNS[1]);
column.setCellEditor(new DefaultCellEditor(new JComboBox(ITEMS)));
container.add(BorderLayout.NORTH, new JTextField());
container.add(BorderLayout.CENTER, new JScrollPane(this.table));
}
public Test6505027(JFrame main) {
Container container = main;
if (INTERNAL) {
JInternalFrame frame = new JInternalFrame();
frame.setBounds(OFFSET, OFFSET, WIDTH, HEIGHT);
frame.setVisible(true);
JDesktopPane desktop = new JDesktopPane();
desktop.add(frame, new Integer(1));
container.add(desktop);
container = frame;
}
if (TERMINATE) {
this.table.putClientProperty(KEY, Boolean.TRUE);
}
TableColumn column = this.table.getColumn(COLUMNS[1]);
column.setCellEditor(new DefaultCellEditor(new JComboBox(ITEMS)));
container.add(BorderLayout.NORTH, new JTextField());
container.add(BorderLayout.CENTER, new JScrollPane(this.table));
}
public Test6802868(JFrame frame) {
JDesktopPane desktop = new JDesktopPane();
this.frame = frame;
this.frame.add(desktop);
this.internal = new JInternalFrame(getClass().getName(), true, true, true, true);
this.internal.setVisible(true);
desktop.add(this.internal);
}
public Test6802868(JFrame frame) {
JDesktopPane desktop = new JDesktopPane();
this.frame = frame;
this.frame.add(desktop);
this.internal = new JInternalFrame(getClass().getName(), true, true, true, true);
this.internal.setVisible(true);
desktop.add(this.internal);
}
public Test6802868(JFrame frame) {
JDesktopPane desktop = new JDesktopPane();
this.frame = frame;
this.frame.add(desktop);
this.internal = new JInternalFrame(getClass().getName(), true, true, true, true);
this.internal.setVisible(true);
desktop.add(this.internal);
}
/**
* InternalFrameDemo Constructor
*/
public InternalFrameDemo() {
setLayout(new BorderLayout());
// preload all the icons we need for this demo
icon1 = resourceManager.createImageIcon("bananas.png",
resourceManager.getString("InternalFrameDemo.bananas"));
icon2 = resourceManager.createImageIcon("globe.png",
resourceManager.getString("InternalFrameDemo.globe"));
icon3 = resourceManager.createImageIcon("package.png",
resourceManager.getString("InternalFrameDemo.package"));
icon4 = resourceManager.createImageIcon("soccer_ball.png",
resourceManager.getString("InternalFrameDemo.soccerball"));
smIcon1 = resourceManager.createImageIcon("bananas_small.png",
resourceManager.getString("InternalFrameDemo.bananas"));
smIcon2 = resourceManager.createImageIcon("globe_small.png",
resourceManager.getString("InternalFrameDemo.globe"));
smIcon3 = resourceManager.createImageIcon("package_small.png",
resourceManager.getString("InternalFrameDemo.package"));
smIcon4 = resourceManager.createImageIcon("soccer_ball_small.png",
resourceManager.getString("InternalFrameDemo.soccerball"));
//<snip>Create desktop pane
// The desktop pane will contain all the internal frames
desktop = new JDesktopPane();
add(desktop, BorderLayout.CENTER);
//</snip>
// Create the "frame maker" palette
createInternalFramePalette();
// Create an initial internal frame to show
JInternalFrame frame1 = createInternalFrame(icon2, DEMO_FRAME_LAYER, 1, 1);
frame1.setBounds(FRAME0_X, FRAME0_Y, FRAME0_WIDTH, FRAME0_HEIGHT);
}
public void activateFrame(JInternalFrame f) {
Container p = f.getParent();
Component[] c;
JDesktopPane d = f.getDesktopPane();
JInternalFrame currentlyActiveFrame = (d == null) ? null : d.getSelectedFrame();
// fix for bug: 4162443
if (p == null) {
// If the frame is not in parent, its icon maybe, check it
p = f.getDesktopIcon().getParent();
if (p == null)
return;
}
// we only need to keep track of the currentActive InternalFrame, if any
if (currentlyActiveFrame == null) {
if (d != null) {
d.setSelectedFrame(f);
}
}
else if (currentlyActiveFrame != f) {
// if not the same frame as the current active
// we deactivate the current
if (currentlyActiveFrame.isSelected()) {
try {
currentlyActiveFrame.setSelected(false);
}
catch (Exception e2) {
}
}
if (d != null) {
d.setSelectedFrame(f);
}
}
f.moveToFront();
}
private static void createAndShowGUI() {
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JDesktopPane desktopPane = new JDesktopPane();
desktopPane.setBackground(DESKTOPPANE_COLOR);
internalFrame = new JInternalFrame("Test") {
@Override
public void paint(Graphics g) {
super.paint(g);
g.setColor(FRAME_COLOR);
g.fillRect(0, 0, getWidth(), getHeight());
}
};
internalFrame.setSize(WIN_WIDTH / 3, WIN_HEIGHT / 3);
internalFrame.setVisible(true);
desktopPane.add(internalFrame);
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(desktopPane, BorderLayout.CENTER);
frame.add(panel);
frame.setSize(WIN_WIDTH, WIN_HEIGHT);
frame.setVisible(true);
frame.requestFocus();
}
/**
* InternalFrameDemo Constructor.
*
* @param swingset the swingset
*/
public InternalFrameDemo(SwingSet2 swingset) {
super(swingset, "InternalFrameDemo"
, "toolbar/JDesktop.gif");
// preload all the icons we need for this demo
icon1 = createImageIcon("ImageClub/misc/fish.gif", getString("InternalFrameDemo.fish"));
icon2 = createImageIcon("ImageClub/misc/moon.gif", getString("InternalFrameDemo.moon"));
icon3 = createImageIcon("ImageClub/misc/sun.gif", getString("InternalFrameDemo.sun"));
icon4 = createImageIcon("ImageClub/misc/cab.gif", getString("InternalFrameDemo.cab"));
smIcon1 = createImageIcon("ImageClub/misc/fish_small.gif", getString("InternalFrameDemo.fish"));
smIcon2 = createImageIcon("ImageClub/misc/moon_small.gif", getString("InternalFrameDemo.moon"));
smIcon3 = createImageIcon("ImageClub/misc/sun_small.gif", getString("InternalFrameDemo.sun"));
smIcon4 = createImageIcon("ImageClub/misc/cab_small.gif", getString("InternalFrameDemo.cab"));
// Create the desktop pane
desktop = new JDesktopPane();
getDemoPanel().add(desktop, BorderLayout.CENTER);
// Create the "frame maker" palette
createInternalFramePalette();
// Create an initial internal frame to show
JInternalFrame frame1 = createInternalFrame(icon1, FIRST_FRAME_LAYER, 1, 1);
frame1.setBounds(FRAME0_X, FRAME0_Y, FRAME0_WIDTH, FRAME0_HEIGHT);
// Create four more starter windows
createInternalFrame(icon1, DEMO_FRAME_LAYER, FRAME_WIDTH, FRAME_HEIGHT);
createInternalFrame(icon3, DEMO_FRAME_LAYER, FRAME_WIDTH, FRAME_HEIGHT);
createInternalFrame(icon4, DEMO_FRAME_LAYER, FRAME_WIDTH, FRAME_HEIGHT);
createInternalFrame(icon2, DEMO_FRAME_LAYER, FRAME_WIDTH, FRAME_HEIGHT);
}
@Override
protected void prepareControls() {
JDesktopPane desktopPane = new JDesktopPane();
JInternalFrame bottomFrame = new JInternalFrame("bottom frame", false, false, false, false);
bottomFrame.setSize(220, 220);
super.propagateAWTControls(bottomFrame);
desktopPane.add(bottomFrame);
bottomFrame.setVisible(true);
JInternalFrame topFrame = new JInternalFrame("top frame", false, false, false, false);
topFrame.setSize(200, 200);
topFrame.add(new JButton("LW Button") {
{
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
lwClicked = true;
}
});
}
});
desktopPane.add(topFrame);
topFrame.setVisible(true);
JFrame frame = new JFrame("Test Window");
frame.setSize(300, 300);
frame.setContentPane(desktopPane);
frame.setVisible(true);
locTopFrame = topFrame.getLocationOnScreen();
locTarget = new Point(locTopFrame.x + bottomFrame.getWidth() / 2, locTopFrame.y + bottomFrame.getHeight()/2);
}
/**
* Creating two JInternalFrames in JDesktopPanes. Put lightweight component into one frame and heavyweight into another.
*/
@Override
protected void prepareControls() {
JDesktopPane desktopPane = new JDesktopPane();
JFrame frame = new JFrame("Test Window");
frame.setSize(300, 300);
frame.setContentPane(desktopPane);
frame.setVisible(true);
JInternalFrame bottomFrame = new JInternalFrame("bottom frame", false, false, false, false);
bottomFrame.setSize(220, 220);
desktopPane.add(bottomFrame);
bottomFrame.setVisible(true);
super.propagateAWTControls(bottomFrame);
JInternalFrame topFrame = new JInternalFrame("top frame", false, false, false, false);
topFrame.setSize(200, 200);
JButton jbutton = new JButton("LW Button") {{
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
lwClicked = true;
}
});
}};
topFrame.add(jbutton);
desktopPane.add(topFrame);
topFrame.setVisible(true);
lLoc = jbutton.getLocationOnScreen();
lLoc.translate(jbutton.getWidth()/2, jbutton.getWidth()/2); //click at middle of the button
}
public void propertyChange(PropertyChangeEvent evt) {
if (SeaGlassLookAndFeel.shouldUpdateStyle(evt)) {
updateStyle((JDesktopPane) evt.getSource());
}
if (evt.getPropertyName() == "ancestor" && taskBar != null) {
taskBar.adjustSize();
}
}
public Test6802868(JFrame frame) {
JDesktopPane desktop = new JDesktopPane();
this.frame = frame;
this.frame.add(desktop);
this.internal = new JInternalFrame(getClass().getName(), true, true, true, true);
this.internal.setVisible(true);
desktop.add(this.internal);
}
private static void createUI(String lookAndFeelString) throws Exception {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame = new JFrame(lookAndFeelString);
desktopPane = new JDesktopPane();
frame.getContentPane().add(desktopPane);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JInternalFrame f = new JInternalFrame("Child ", true, true,
true, true);
f.setSize(200, 300);
f.setLocation(20, 20);
try {
f.setIcon(true);
} catch (PropertyVetoException ex) {
errorMessage += ex.getMessage() + "\n";
}
desktopPane.add(f);
f.setVisible(true);
frame.setSize(500, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
public Test6802868(JFrame frame) {
JDesktopPane desktop = new JDesktopPane();
this.frame = frame;
this.frame.add(desktop);
this.internal = new JInternalFrame(getClass().getName(), true, true, true, true);
this.internal.setVisible(true);
desktop.add(this.internal);
}
public GUI()
{
setTitle("AgreementMakerLight");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setDefaultLookAndFeelDecorated(true);
amlMenuBar = new AMLMenuBar();
setJMenuBar(amlMenuBar);
desktop = new JDesktopPane();
desktop.setLayout(new BorderLayout());
//Get the effective screen size
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
Dimension screenSize = env.getMaximumWindowBounds().getSize();
//Get the insets (shouldn't be necessary, but just in case)
Insets insets = this.getInsets();
int w = insets.left + insets.right + 10;
int h = insets.top + insets.bottom;
//Determine width and height of the panels
int width = screenSize.width - w;
int panel = 85;
int viewer = screenSize.height - h - panel - (4*amlMenuBar.getPreferredSize().height);
//Set their dimensions
panelMin = new Dimension(width - 20, panel);
panelMax = new Dimension(width, panel);
viewerMin = new Dimension(width, viewer);
viewerMax = new Dimension(width, viewer);
resourcePanel = new ResourcePanel(panelMax,panelMin);
desktop.add(resourcePanel,BorderLayout.NORTH);
alignPanel = new AlignmentPanel(viewerMax,viewerMin);
desktop.add(alignPanel);
setContentPane(desktop);
this.pack();
setExtendedState(JFrame.MAXIMIZED_BOTH);
setVisible(true);
}
/**
* Maps {@code JInternalFrame.getDesktopPane()} through queue
*/
public JDesktopPane getDesktopPane() {
return (runMapping(new MapAction<JDesktopPane>("getDesktopPane") {
@Override
public JDesktopPane map() {
return ((JInternalFrame) getSource()).getDesktopPane();
}
}));
}
public Test6802868(JFrame frame) {
JDesktopPane desktop = new JDesktopPane();
this.frame = frame;
this.frame.add(desktop);
this.internal = new JInternalFrame(getClass().getName(), true, true, true, true);
this.internal.setVisible(true);
desktop.add(this.internal);
}
public Test6802868(JFrame frame) {
JDesktopPane desktop = new JDesktopPane();
this.frame = frame;
this.frame.add(desktop);
this.internal = new JInternalFrame(getClass().getName(), true, true, true, true);
this.internal.setVisible(true);
desktop.add(this.internal);
}