InternalFrame demo : InternalFrame « Swing JFC « Java






InternalFrame demo

InternalFrame demo
  
import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;

public class DesktopSample {

  public static void main(String[] args) {
    String title = "Desktop Sample";
    JFrame frame = new JFrame(title);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JDesktopPane desktop = new JDesktopPane();
    JInternalFrame internalFrames[] = {
        new JInternalFrame("Can Do All", true, true, true, true),
        new JInternalFrame("Not Resizable", false, true, true, true),
        new JInternalFrame("Not Closable", true, false, true, true),
        new JInternalFrame("Not Maximizable", true, true, false, true),
        new JInternalFrame("Not Iconifiable", true, true, true, false) };

    InternalFrameListener internalFrameListener = new InternalFrameIconifyListener();

    for (int i = 0, n = internalFrames.length; i < n; i++) {
      desktop.add(internalFrames[i]);
      internalFrames[i].setBounds(i * 25, i * 25, 200, 100);
      internalFrames[i].addInternalFrameListener(internalFrameListener);

      JLabel label = new JLabel(internalFrames[i].getTitle(),  JLabel.CENTER);
      Container content = internalFrames[i].getContentPane();
      content.add(label, BorderLayout.CENTER);

      internalFrames[i].setVisible(true);
    }

    JInternalFrame palette = new JInternalFrame("Palette", true, false,  true, false);
    palette.setBounds(350, 150, 100, 100);
    palette.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);
    desktop.add(palette, JDesktopPane.PALETTE_LAYER);
    palette.setVisible(true);

    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);

    Container content = frame.getContentPane();
    content.add(desktop, BorderLayout.CENTER);
    frame.setSize(500, 300);
    frame.setVisible(true);
  }
}

class InternalFrameIconifyListener extends InternalFrameAdapter {
  public void internalFrameIconified(InternalFrameEvent internalFrameEvent) {
    JInternalFrame source = (JInternalFrame) internalFrameEvent.getSource();
    System.out.println("Iconified: " + source.getTitle());
  }

  public void internalFrameDeiconified(InternalFrameEvent internalFrameEvent) {
    JInternalFrame source = (JInternalFrame) internalFrameEvent.getSource();
    System.out.println("Deiconified: " + source.getTitle());
  }
}

           
         
    
  








Related examples in the same category

1.A quick demonstration of setting up an internal frame in an applicationA quick demonstration of setting up an internal frame in an application
2.A simple extension of the JInternalFrame class that contains a list
3.JDesktopPane demoJDesktopPane demo
4.Working with Internal Frames within a Desktop
5.Internal Frames DemoInternal Frames Demo
6.JDesktopPane Cascade DemoJDesktopPane Cascade Demo
7.Java X WindowsJava X Windows
8.Desktop Manager DemoDesktop Manager Demo
9.Internal Frame Listener Demo Internal Frame Listener Demo
10.Layered Pane DemoLayered Pane Demo
11.LayeredPane Demo 2: Custom MDILayeredPane Demo 2: Custom MDI
12.LayeredPane Demo 3: Custom MDILayeredPane Demo 3: Custom MDI
13.LayeredPane Demo 4: Custom MDILayeredPane Demo 4: Custom MDI
14.Implements InternalFrameListenerImplements InternalFrameListener
15.InternalFrameEvent DemoInternalFrameEvent Demo
16.A few interesting things using JInternalFrames, JDesktopPane, and DesktopManagerA few interesting things using JInternalFrames, JDesktopPane, and DesktopManager
17.A quick setting up an Internal Frame in an applicationA quick setting up an Internal Frame in an application
18.Interesting things using JInternalFrames, JDesktopPane, and DesktopManager 2Interesting things using JInternalFrames, JDesktopPane, and DesktopManager 2
19.Make a JInternalFrame a tool window
20.Move JInternalFrame To Front
21.This program demonstrates the use of internal framesThis program demonstrates the use of internal frames