Internal Frames problem

Hi,
I am writing a piece of code where I want to able to choose from a menu a screen that displays multiple graphs (using Internal frames.) I am using cardlayout to bring up the various options I choose from the menu. I have simplified my program as much as possible but I still seem to be getting the same error
Exception in thread "main" java.lang.IllegalArgumentException: adding a window to a container .......
I know I shouldn't be adding a window to a container but I can't see how I can change my code so it has the functionality I desire.
Here is the code I am using
import java.awt.*;
import javax.swing.*;
public class Test extends JFrame
     public Test()
         JPanel card1 = new JPanel();
         card1.add(new InternalFrameDemo());
          getContentPane().add(card1);
    public static void main(String[] args)
          Test frame = new Test();
          frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
          frame.setSize(200, 200);
          frame.setLocationRelativeTo( null );
          frame.setVisible(true);
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class InternalFrameDemo extends JFrame
    JDesktopPane desktop;
    static final int xOffset = 30, yOffset = 30;
    private JLabel graph1;
    private String Graph1;
    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);
        //Make dragging a little faster but perhaps uglier.
        desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    //Create a new internal frame.
    protected void createFrame() {
        MyInternalFrame frame = new MyInternalFrame();
        frame.setVisible(true);
        desktop.add(frame);
        try {
            frame.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {}
    //Quit the application.
    protected void quit() {
        System.exit(0);
   public void MyInternalFrame() {
     System.out.println("graph1");
     graph1 = new JLabel("", 
                   new ImageIcon("../images/Graph1.jpg"),
                   JLabel.CENTER);
     getContentPane().add(graph1);
     //...Then set the window size or call pack...
     setSize(500,550);
}If anyone could point me in the right direction it would be great. Thanks in advance!

But I actually do not understand what that card layout thing is all about. If you want to hide/show internal frames you can simply use setVisible() and setSelected() like examplified below (I did put all code in the same file for my convenince). I have put a text in the label so that you can see that it is replaced. Using aJLabel to show an image is however a little bit weird.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
class MyInternalFrame extends JInternalFrame
  private JLabel graph1;
  public MyInternalFrame(String text)
    graph1 = new JLabel(text, 
                        new ImageIcon("../images/Graph1.jpg"),
                        JLabel.CENTER);
    getContentPane().add(graph1);
    setSize(500,550);
public class InternalFrameDemo extends JFrame
  private JDesktopPane desktop;
  private final MyInternalFrame[] frames;
  public InternalFrameDemo()
    super("InternalFrameDemo");
    frames = new MyInternalFrame[3];
    //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
    setContentPane(desktop);
    frames[0] = createFrame("Hello world!");
    frames[1] = createFrame("Hello again, world!");
    frames[2] = createFrame("Goodbye cruel world!");
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    setSize(500, 500);
    Thread animThread = new Thread()
        public void run()
          for (int i = 0; i < frames.length; ++i)
            final int frameId = i;
            SwingUtilities.invokeLater(new Runnable()
                public void run()
                  // Hide frame that is showing.
                  if (frameId != 0)
                    frames[frameId - 1].setVisible(false);
                  System.out.println("Replacing image: " + frameId);
                  frames[frameId].setVisible(true);
                  try
                    frames[frameId].setSelected(true);
                  catch (java.beans.PropertyVetoException exc)
                    exc.printStackTrace();
            try
              Thread.sleep(3000);
            catch (InterruptedException exc)
              exc.printStackTrace();
    animThread.start();
  //Create a new internal frame.
  protected MyInternalFrame createFrame(String text)
    MyInternalFrame frame = new MyInternalFrame(text);
    desktop.add(frame);
    return frame;
  public static void main(String[] args)
    JFrame frame = new InternalFrameDemo();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}Using lazy initialization where you postpone the creation of an internal frame until it is actually shown would be an improvement.
The setVisible/Selected() call can of course be triggered by something else in your application.
Note that changes of swing components shall be made in the EDT.

Similar Messages

  • A Internal frame problem: Please help me

    How can you add a panel to internal frame and show it. I add a image buffer to a panel and then I want to add that panel to internal frame which exists in a main frame. Please help me with code snippet as I am unable to it since morning and struck with my progress in my work. I will be thanki ful/
    regards,
    Ravi.

    Have a look at the code I took from the excellent FREE java swing book you can get here http://www.manning.com/sbe/
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    public class CommonLayouts extends JFrame {
    public Integer LAYOUT_FRAME_LAYER = new Integer(1);
    public CommonLayouts() {
    super("Common Layout Managers");
    setSize(500, 460);
    JDesktopPane desktop = new JDesktopPane();
    getContentPane().add(desktop);
    JInternalFrame fr1 =
    new JInternalFrame("FlowLayout", true, true);
    fr1.setBounds(10, 10, 150, 150);
    Container c = fr1.getContentPane();
    c.setLayout(new FlowLayout());
    c.add(new JButton("1"));
    c.add(new JButton("2"));
    c.add(new JButton("3"));
    c.add(new JButton("4"));
    desktop.add(fr1, 0);
    fr1.show();
    JInternalFrame fr2 =
    new JInternalFrame("GridLayout", true, true);
    fr2.setBounds(170, 10, 150, 150);
    c = fr2.getContentPane();
    c.setLayout(new GridLayout(2, 2));
    c.add(new JButton("1"));
    c.add(new JButton("2"));
    c.add(new JButton("3"));
    c.add(new JButton("4"));
    desktop.add(fr2, 0);
    fr2.show();
    JInternalFrame fr3 =
    new JInternalFrame("BorderLayout", true, true);
    fr3.setBounds(330, 10, 150, 150);
    c = fr3.getContentPane();
    c.add(new JButton("1"), BorderLayout.NORTH);
    c.add(new JButton("2"), BorderLayout.EAST);
    c.add(new JButton("3"), BorderLayout.SOUTH);
    c.add(new JButton("4"), BorderLayout.WEST);
    desktop.add(fr3, 0);
    fr3.show();
    JInternalFrame fr4 = new JInternalFrame("BoxLayout - X",
    true, true);
    fr4.setBounds(10, 170, 250, 80);
    c = fr4.getContentPane();
    c.setLayout(new BoxLayout(c, BoxLayout.X_AXIS));
    c.add(new JButton("1"));
    c.add(Box.createHorizontalStrut(12));
    c.add(new JButton("2"));
    c.add(Box.createGlue());
    c.add(new JButton("3"));
    c.add(Box.createHorizontalGlue());
    c.add(new JButton("4"));
    desktop.add(fr4, 0);
    fr4.show();
    JInternalFrame fr5 = new JInternalFrame("BoxLayout - Y",
    true, true);
    fr5.setBounds(330, 170, 150, 200);
    c = fr5.getContentPane();
    c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS));
    c.add(new JButton("1"));
    c.add(Box.createVerticalStrut(10));
    c.add(new JButton("2"));
    c.add(Box.createGlue());
    c.add(new JButton("3"));
    c.add(Box.createVerticalGlue());
    c.add(new JButton("4"));
    desktop.add(fr5, 0);
    fr5.show();
    JInternalFrame fr6 =
    new JInternalFrame("SpringLayout", true, true);
    fr6.setBounds(10, 260, 250, 170);
    c = fr6.getContentPane();
    c.setLayout(new SpringLayout());
    c.add(new JButton("1"), new SpringLayout.Constraints(
    Spring.constant(10),
    Spring.constant(10),
    Spring.constant(120),
    Spring.constant(70)));
    c.add(new JButton("2"), new SpringLayout.Constraints(
    Spring.constant(160),
    Spring.constant(10),
    Spring.constant(70),
    Spring.constant(30)));
    c.add(new JButton("3"), new SpringLayout.Constraints(
    Spring.constant(160),
    Spring.constant(50),
    Spring.constant(70),
    Spring.constant(30)));
    c.add(new JButton("4"), new SpringLayout.Constraints(
    Spring.constant(10),
    Spring.constant(90),
    Spring.constant(50),
    Spring.constant(40)));
    c.add(new JButton("5"), new SpringLayout.Constraints(
    Spring.constant(120),
    Spring.constant(90),
    Spring.constant(50),
    Spring.constant(40)));
    desktop.add(fr6, 0);
    fr6.show();
    desktop.setSelectedFrame(fr6);
    public static void main(String argv[]) {
    CommonLayouts frame = new CommonLayouts();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

  • Internal frame dragging perfermance problem in JDK1.4.1

    Hi there,
    When using internal frame with outline(not faster or LIVE_DRAG_MODE) property with JDK 1.4.1_01 (windows), the speed of internal frame dragging is terrible(very very slow).
    The same code runs fine with JDK1.3.X, and it's performance(dragging speed) is acceptable(not very good, so so) when using JDK 1.4.0_X.
    I've tried both motheds to set the property as follow, and got the same result:
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    desktop.putClientProperty("JDesktopPane.dragMode", "outline");
    But, after I commented the line: g.setXORMode(Color.white); //line Num: 279
    in the class javax.swing.DefaultDesktopManager.java, the speed of dragging is very well(as same as when running with JDK1.3.X).
    My qestions are:
    - How can I improve the internal frame dragging performance in JDK 1.4.1_01(windows)?
    - Does my testing mean to a bug in the implementation of the abstract method Graphics.setXORMode() in the JDK 1.4.1_01 windows version ?
    TIA
    In terms of the test case, we may just use the follows:
    http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/InternalFrameDemo.java
    http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/MyInternalFrame.java

    Anyone know if this is registered as a bug? I couldn't find it.

  • Openinig internal frames by clicking menuitems

    Hi,
    I have been trying to open internal frames by clicking menu items but
    have not been able to do so because menuitems support only action listeners and not all mouse event listeners.
    Actually I wanted the event to return the frame n which the event has occured
    e.g., event,getframe(), so that I could create an internal frame in the same frame.
    But such kind of function is unavailable.
    Kindly suggest something...the code is given below (it works perfectly)..it need a text file from which the menuitems are read. This is also given below:
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.lang.*;
    import java.io.*;
    import javax.swing.plaf.metal.*;
    import javax.swing.*;
    import javax.swing.undo.*;
    class Action extends JFrame
         ActionListener FListener = new ActionListener()
               public void actionPerformed(ActionEvent event)
                  {System.out.println("Menu item " + event.getActionCommand(  ) +"  of File Menu was pressed.");}
        ActionListener EListener = new ActionListener()
               public void actionPerformed(ActionEvent event)
                  {System.out.println("Menu item " + event.getActionCommand(  ) +"  of Edit Menu was pressed.");}
        ActionListener VListener = new ActionListener()
               public void actionPerformed(ActionEvent event)
                  {System.out.println("Menu item " + event.getActionCommand(  ) +"  of View Menu was pressed.");}
        ActionListener TListener = new ActionListener()
               public void actionPerformed(ActionEvent event)
                  {System.out.println("Menu item " + event.getActionCommand(  ) +"  of Tools Menu was pressed.");}
        ActionListener HListener = new ActionListener()
               public void actionPerformed(ActionEvent event)
                  {System.out.println("Menu item " + event.getActionCommand(  ) +"  of Help Menu was pressed.");}
         /*     protected class MyUndoableEditListener  implements UndoableEditListener
                  protected UndoManager undo = new UndoManager();
                  public void undoableEditHappened(UndoableEditEvent e)
                 //Remember the edit and update the menus
                 undo.addEdit(e.getEdit());
                 undoAction.updateUndoState();
                 redoAction.updateRedoState();
          class framecreator extends JFrame
               public JFrame CreateFrame(JMenuBar m)
             JDesktopPane jdp= new JDesktopPane();
              JFrame.setDefaultLookAndFeelDecorated(true);       
            JFrame frame = new JFrame("PEA");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         
            frame.setContentPane(jdp);
            jdp.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);          
            frame.setJMenuBar(m);       
            frame.pack();
            frame.setVisible(true);
            frame.setSize(600,600);
            frame.setLocation(100,100);
            return frame;
          class internalframecreator extends JFrame
             public JInternalFrame CreateInternalFrame(JFrame f)
              Container cp= f.getContentPane();
              JInternalFrame jif = new JInternalFrame("internal frame",true,true,true,true);
             cp.add(jif);
             jif.pack();
             jif.setVisible(true);
             jif.setSize(300,300);
             jif.setLocation(80,80);
             return jif;    
      class menucreator
         public String[] filereader()
              String[] menuitems=new String[21];
              int i=0,j=0;
              String record = null;            
                   for(int h=0;h<21;h++){ menuitems[h]=null;}
               try { 
                    FileReader fr = new FileReader("projectconfig2.txt");  
                     BufferedReader br = new BufferedReader(fr);
                         while ( (record=br.readLine()) != null )
                           StringTokenizer st = new StringTokenizer(record,"\n");
                             while (st.hasMoreTokens())
                          menuitems= st.nextToken();
         System.out.println(menuitems[i]);
    i++;
                   /* StringTokenizer st1 = new StringTokenizer(record,"\n");
         while (st1.hasMoreTokens())
         while ( (record=br.readLine()) != null )
         StringTokenizer st2 = new StringTokenizer(record,":");
         while (st2.hasMoreTokens())
         menuitems[i][j]= st2.nextToken();
         System.out.println(menuitems[i][j]);
              j++;      
         i++;
              } catch(IOException e)
         System.out.println("Error reading file");
         return (menuitems);
         public JMenuBar CreateMenu(Action a, String menuitems[])
    JMenuBar mb = new JMenuBar();
    JMenu fileB = new JMenu(menuitems[0]);
    JMenu editB = new JMenu(menuitems[8]);
    JMenu viewB = new JMenu(menuitems[11]);
    JMenu toolsB = new JMenu(menuitems[14]);
    JMenu helpB = new JMenu(menuitems[18]);
    mb.add(fileB);
    mb.add(editB);
    mb.add(viewB);
    mb.add(toolsB);
    mb.add(helpB);
    JMenuItem newpolicyB = new JMenuItem(menuitems[1]);
    newpolicyB.addActionListener(a.FListener);
    //newpolicyB.addUndoableEditListener(new MyUndoableEditListener());
    JMenuItem openB = new JMenuItem(menuitems[2]);
    openB.addActionListener(a.FListener);
    JMenuItem saveB = new JMenuItem(menuitems[3]);
    saveB.addActionListener(a.FListener);
    JMenuItem saveasB = new JMenuItem(menuitems[4]);
    saveasB.addActionListener(a.FListener);
    JMenuItem printxmlB = new JMenuItem(menuitems[5]);
    printxmlB.addActionListener(a.FListener);
    JMenuItem printreadablepolicyB = new JMenuItem(menuitems[6]);
    printreadablepolicyB.addActionListener(a.FListener);
    JMenuItem exitB = new JMenuItem(menuitems[7]);
    exitB.addActionListener(a.FListener);
    JMenuItem undoB = new JMenuItem(menuitems[9]);
    undoB.addActionListener(a.EListener);
    JMenuItem redoB = new JMenuItem(menuitems[10]);
    redoB.addActionListener(a.EListener);
    JMenuItem xmlB = new JMenuItem(menuitems[12]);
    xmlB.addActionListener(a.VListener);
    JMenuItem readablepolicyB = new JMenuItem(menuitems[13]);
    readablepolicyB.addActionListener(a.VListener);
    JMenuItem validateB = new JMenuItem(menuitems[15]);
    validateB.addActionListener(a.TListener);
    JMenuItem signandpublishB = new JMenuItem(menuitems[16]);
    signandpublishB.addActionListener(a.TListener);
    JMenuItem optionsB = new JMenuItem(menuitems[17]);
    optionsB.addActionListener(a.TListener);
    JMenuItem pemanualB = new JMenuItem(menuitems[19]);
    pemanualB.addActionListener(a.HListener);
    JMenuItem aboutB = new JMenuItem(menuitems[20]);
    aboutB.addActionListener(a.HListener);
    fileB.add(newpolicyB);
    fileB.add(openB);
    fileB.add(saveB);
    fileB.add(saveasB);
    fileB.add(printxmlB);
    fileB.add(printreadablepolicyB);
    fileB.add(exitB);
    editB.add(undoB);
    editB.add(redoB);
    viewB.add(xmlB);
    viewB.add(readablepolicyB);
    toolsB.add(validateB);
    toolsB.add(signandpublishB);
    toolsB.add(optionsB);
    helpB.add(pemanualB);
    helpB.add(aboutB);
    mb.setSize(300,200);
    mb.setVisible(true);
    return mb;
    public class project
    public static void main(String args[])
              Action a =new Action();           
              framecreator fc=new framecreator();           
         menucreator mc=new menucreator();     
         internalframecreator ifc= new internalframecreator();          
         ifc.CreateInternalFrame(fc.CreateFrame(mc.CreateMenu(a,mc.filereader())));
    The text file called projectconfig2.txt
    File
    New Policy
    Open...
    Save
    Save As...
    Print XML
    Print Readable Policy
    Exit
    Edit
    Undo
    Redo
    View
    XML
    Readable Policy
    Tools
    Validate
    Sign & Publish
    Options
    Help
    PE Manual
    About

    The problem is that you are adding the JInternalFrame to the JFrame's contentPane when it should be added to the JDesktopPane. See your code ...
    public JInternalFrame CreateInternalFrame( JFrame  f )
         Container  cp = f.getContentPane();
         JInternalFrame jif = new JInternalFrame("internal frame",true,true,true,true);
         cp.add( jif );

  • How to get Internal frames as well as a background image in a JFrame?

    Hi All,
    Here's my problem. I have a JFrame with a background image that I got by overridding the paintComponent() method of a JPanel and setting as the contentPane of a JFrame. Works great.
    Now what I want is to use internal frames with this Frame a la JInternalFrame classes. But you need to create a JDesktopPane object and set this as the contentPane of the JFrame to get internal frames to work, right? Is there a way for me to have my cake and eat it so I get both internal frames and a background image? Thanks!

    Hmmm,
    so simple, why didn't I think of that? Damn Mondays!
    thanks very much!

  • JAVA Frame problem

    Hi,
    I hav a problem in JAVA. I have a main frame. This has an internal
    frame as its compnent. The size(height) of internal frame is more
    than the main frame. I want the a to vertically scroll in main frame
    to see the entire internal frame.
         The following code i tried with JSCrollPane gives me only
    horizontall scrolling , so i can see entire width, but no verticall
    scroll to see entire height of internal frame.
         Can u solve this problem.
    Bye,
    Pradeep
    import java.awt.*;
    import javax.swing.*;
    public class Main extends JFrame
         JInternalFrame jInternal;
         JScrollPane jPane;
         Main()
              jInternal = new JInternalFrame();
              jInternal.setSize(200,600);//Internal Frame height bigger
              jPane = new JScrollPane(jInternal);
              getContentPane().add(jPane);
              setSize(200,200);//Frame height smaller
              jInternal.show();
         public static void main(String a[])
              Main m = new Main();
              m.show();     

    Hi.. This might help:
    JScrollPane jPane;
    jPane = new JScrollPane(jInternal,
    ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    U can change those constants so that it shows the scrollbars at all time.. Now they only appear when needed..

  • Modal Internal Frames and JCombos

    Hi,
    I'm trying to create a modal internal frame as suggested in Sun's TechTip:
    http://developer.java.sun.com/developer/JDCTechTips/2001/tt1220.html
    All I need is to block the input for the rest of the GUI, I don't care about real modality (the setVisible() call returns immediately).
    I need to have a JComboBox in my internal frame. It turns out that under JDK1.4.0/1.4.1 the list for the combo is visible only with the Windows Look And Feel, while in every other JDK version it's not visible, except for the portion falling out of the internal frame.
    The code to verify this follows. Does anybody know how to fix this? I've opened a bug for it, but I was wondering if someone can help in the forum...
    Run the application passing "Windows" or "CDE/Motif", click on "open" and play with the combo to observe the result.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class Modal {
    static class ModalAdapter
    extends InternalFrameAdapter {
    Component glass;
    public ModalAdapter(Component glass) {
    this.glass = glass;
    // Associate dummy mouse listeners
    // Otherwise mouse events pass through
    MouseInputAdapter adapter =
    new MouseInputAdapter(){};
    glass.addMouseListener(adapter);
    glass.addMouseMotionListener(adapter);
    public void internalFrameClosed(
    InternalFrameEvent e) {
    glass.setVisible(false);
    public static void main(String args[]) {
    System.out.println("Installed lookAndFeels:");
    UIManager.LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels();
    for(int i=0; i<lafInfo.length; i++) {
    System.out.println(lafInfo.getName());
    String lookAndFeel = null;
    if (args.length>0)
    lookAndFeel = args[0];
    initLookAndFeel(lookAndFeel);
    final JFrame frame = new JFrame(
    "Modal Internal Frame");
    frame.setDefaultCloseOperation(
    JFrame.EXIT_ON_CLOSE);
    final JDesktopPane desktop = new JDesktopPane();
    ActionListener showModal =
    new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    // Manually construct a message frame popup
    JOptionPane optionPane = new JOptionPane();
    optionPane.setMessage("Hello, World");
    optionPane.setMessageType(
    JOptionPane.INFORMATION_MESSAGE);
    // JInternalFrame modal = optionPane.
    // createInternalFrame(desktop, "Modal");
                        JInternalFrame modal = new JInternalFrame("test", true, true, true);
    JPanel jp = (JPanel )modal.getContentPane();
              JComboBox jcb = new JComboBox(new String[]{"choice a", "choice b"});
    jp.setLayout(new BorderLayout());
              jp.add(jcb,BorderLayout.NORTH);
              jp.add(new JTextArea(),BorderLayout.CENTER);
    // create opaque glass pane
    JPanel glass = new JPanel();
    glass.setOpaque(false);
    // Attach modal behavior to frame
    modal.addInternalFrameListener(
    new ModalAdapter(glass));
    // Add modal internal frame to glass pane
    glass.add(modal);
    // Change glass pane to our panel
    frame.setGlassPane(glass);
    // Show glass pane, then modal dialog
    modal.setVisible(true);
    glass.setVisible(true);
    System.out.println("Returns immediately");
    JInternalFrame internal =
    new JInternalFrame("Opener");
    desktop.add(internal);
    JButton button = new JButton("Open");
    button.addActionListener(showModal);
    Container iContent = internal.getContentPane();
    iContent.add(button, BorderLayout.CENTER);
    internal.setBounds(25, 25, 200, 100);
    internal.setVisible(true);
    Container content = frame.getContentPane();
    content.add(desktop, BorderLayout.CENTER);
    frame.setSize(500, 300);
    frame.setVisible(true);
    private static void initLookAndFeel(String lookAndFeel) {
    String lookAndFeelClassName = null;
    UIManager.LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels();
    for(int i=0; i<lafInfo.length; i++) {
    if (lafInfo[i].getName().equals(lookAndFeel)) {
    lookAndFeelClassName = lafInfo[i].getClassName();
    if (lookAndFeelClassName == null)
    System.err.println("No class found for lookAndFeel: "+ lookAndFeel);
    try {
    UIManager.setLookAndFeel(lookAndFeelClassName);
    } catch (ClassNotFoundException e) {
    System.err.println("Couldn't find class for specified look and feel:"
    + lookAndFeel);
    System.err.println("Did you include the L&F library in the class path?");
    System.err.println("Using the default look and feel.");
    } catch (UnsupportedLookAndFeelException e) {
    System.err.println("Can't use the specified look and feel ("
    + lookAndFeel
    + ") on this platform.");
    System.err.println("Using the default look and feel.");
    } catch (Exception e) {
    System.err.println("Couldn't get specified look and feel ("
    + lookAndFeel
    + "), for some reason.");
    System.err.println("Using the default look and feel.");
    e.printStackTrace();

    Hi,
    Had exactly the same problem. Seems there are plenty of similar problems all related to the glass pane, so have solved the problem here by putting the event-blocking panel onto the MODAL_LAYER of the layered pane, rather than replacing the glass pane. Otherwise pretty much the same technique - you may need a property change listener to track changes in the size of the layered pane
    something like ...
    layer = frame.getLayeredPane();
    glass.setSize (layer.getSize()); // will need to track size
    glass.add (modal);
    layer.add(glass, JLayeredPane.MODAL_LAYER, 0);
    I've modified the original examples so the frames can be re-used so you may have to play around with the example a bit
    Hope it helps
    cheers.

  • Image icon on internal frame disappearing and re-appearing

    I have just upgraded to jdk 1.4.1-b21 from 1.4.0_01-b03 and have noticed that after adding an Internal Frame to a desktop and moving the mouse over the image icon in the left hand corner the image disappears. The image re-appears again, once I presume, when the desktop and its frames are repainted.
    Is this a bug or has something changed between the two jdk's.
    Thanks.
    Steve.

    Hi,
    I attempted the Disk Utility Repair but it did not work.
    So I disabled the application 'StickyWindows' and this resolved the problem.
    Hope this helps.

  • How to display internal frame on click event from another internal frame

    hi me developing desktop application in netbean. i have some problem. plz reply me as soon as possible. feedback me on [email protected]
    1. I want to invoke an Internal Frame by click event that is in another internal frame. how i do it. I tried my best
    2. how can i call reports (ireports) from swing application

    Read the JInternalFrame API. You will find a link to the Swing tutorial on "How to Use Internal Frames" which contains a working example.

  • Plz help me with the internal frames

    hi,.
    i have design mainframe of my application contain some jinternalframes
    .but these internal frames are not properly working since my mainframe contain borderlayout , mainframe also contain some menubar ,toolbar,jtable .so whenever i call my internalframes these frames just get behind my jtable . whenever i shift the border layout to
    east or west or north the internalframes just get shift inthe given space .actually by default i have border layout as center.when shift my layout to flow layout menubar,toolbar, every thing get shifted , so another problems occur. if iam using flow layout the size of the internalframes remain the same as setted in the code. else in the borderlayout it acqurie the whole of the desktopPane.and no resize code works on it. setsize,setbound,sestpreffredsize,dimension non of these method work.
    thanx for now hope u will slove my problems .

    Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/internalframe.html]How to Use Internal Frames. You add a JDesktopPane to the contentPane and then add the JInternalFrames to the desktop pane.
    If you want to add other components to the GUI then you add them to some other part of the content pane. You don't mix other Swing components and internal frame on the desktop pane.

  • Visibilty of Internal frame in a parent JFrame when it maximize

    i'm working projects on GUI MDI Form.So i've a problem that when we maximize the internal frame
    it should go back to Menu bar of parent frame MDI or title bar of perent frame MDI. Minimisable button and maxim button and closed button should be appear on the back of component where'r the internal going .
    means we can operate the internal frame minimise and close.
    So if anyone who worked on that please help me..............................................

    Without SSCCE, we can't help you!

  • Getting the size of an internal frame?

    Hi allm
    I want to be able to get the size of an internal frame. I have set the size of the main JFrame to that of Windows by calling Toolkit.getScreenSize(); But i can't seem to find an equivalent for internal frames.
    Basically I have two components in the internal frame that I want to have equal width. I was going to find out the size of the internal frame and then half it and applay a horizontal strut to each component.
    If there is a better way of doing it i'm open to suggestions but any help at all is much appreciated
    Thanks
    Dylan
    BorderLayout border = new BorderLayout();       
             content.setLayout(border);
             Box left = Box.createVerticalBox();
             left.add(Box.createHorizontalStrut(400));
             JPanel Create = new JPanel();
                 Create.setBorder(new TitledBorder (new EtchedBorder(), "Create Database"));
                 left.add(Create);
                 Box right = Box.createVerticalBox();
                 right.add(Box.createHorizontalStrut(400));
                 JPanel Help = new JPanel();
                 Help.setBorder(new TitledBorder (new EtchedBorder(), "Help"));
                 right.add(Help);
                 content.add(left, BorderLayout.CENTER);
                 content.add(right, BorderLayout.CENTER);

    The situation is that I have a class that has about 80
    instance fields of basic data types. But it was
    getting overly complicated. As a number of these
    fields related to year and day data I tried to
    re-write with GregorianCalendar instead.
    There are in the region of 45,000 instance of my clas
    being held in an array, however when I tried to use my
    modified class (with the Calendar fields replacing the
    basic data types) I kept running into OutOfMemoryError
    after about 25,000 instances were created. So I
    figured that the GregorianCalendar class must be
    eating up my memory. Was intrigued, but couldn't find
    out how to calculate the size of my new class.
    Hmmm, serialize it you say? Ok, I'll try that.ok don't do that ;)
    ummm i was giving advice assuming (incorrectly i turns out) that you were trying to see how much space the serialized object would take up when written to disk or over a network etc.
    this does not appear to be your problem.
    so here are my new more informed suggestions.
    1) if you were going to write out the "data" parts of your object so
    it could be re-created what would they be. i'm thinking you could
    just boil it all down maybe to a long as in Date.getTime(); then
    you could have a long[] array with 45,000 slots. this should take up far less memory than having myObject[] with 45,000 slots. then you
    could have one actual object that you insert the data into to play
    around with. this may not be the idealists solution but if you have a
    lot of objects you may not want to carry around all the excess
    stuff.
    2) as an aside you say you tried to re-write the GregorianCalendar...
    have your tried extending it or extending Calendar. the idea of
    extending other non-final classes is you can provide your own
    implementation of some things or add totally new methods without having
    to re-write an existing class.
    just some ideas...

  • Canvas on the Internal Frame overlap the Menus.!!!

    hi friends
    i have added canvas on the internal frame(contentpane).
    when internal frame appears on the screen menus are being overlapped.
    it means if i open the menu they will be hide behind canvas and can not be seen.
    plzz guide me what to do?

    This is a typical problem when mixing Swing (JFrame) components with AWT components (Canvas). Make sure you stick to only one of these GUI packages when implementing your own gui.
    Have a look at the java tutorial.
    http://java.sun.com/docs/books/tutorial/uiswing/painting/overview.html
    Manuel Amago.

  • How can I use internal frames with buttons to call others internal frames?

    Hello.
    I'm building a MDI-application using JFrames and several JInternalFrames, but I have problems.
    A JFrame has JMenuBar with JMenu and JMenuItem. One of these, call the first JInternal that has its interface. In this interface has a button that call other type (a class extension of JInternalFrame) JInternalFrame.
    When I clicked button happen a exception (java.lang.NullPointer).
    What happening?
    Help me, please.

    What i usually do is to give my desktop to my internal frames. So within the internalframe, you can use your desktop and add other internal frames to it.
    The code should look something like the following.
    desktop = your JDesktopPane
    MyInternalFrame = an InternalFrame
    AnotherMyInternalFrame = another InternalFrame
    public class MyInternalFrame extends JInternalFrame implements ActionListener
      private JButton jb = new JButton("Launch");
      private JLayeredPane desktop = null;
      public MyInternalFrame(JLayeredPane desktop)
        this.desktop = desktop;
        getContentPane().add(jb);
        jb.addActionListener(this);
      public void actionPerformed(ActionEvent ae)
        if (ae.getSource() == jb)
          desktop.add(new AnotherMyInternalFrame(desktop),JLayeredPane.DEFAULT_LAYER);
    }

  • JInteral Frame Problem

    Hi people, i've a big problem that i can't solve. The issue is that i've build a program with a JFrame containing a JTabbedPane. In the first tab of the JTabbedPane the program has a JSplitPane (Vertical) and this JSplitPane contains two tables. The JTabbedPane has a another tab with other table.
    The JFrame has a top menu (Files,Functions,etc). The problem is when i select one of the submenu's items i want to display a JInternalFrame (in the center of the main JFrame) and i don't know how to do that. I've read that i need a JDesktopPane but i don't where i put it.
    I hope someone can help me...

    -- try this very simple code, you can experiment from that:
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class test  extends JFrame implements ActionListener{ 
         public static void main(String args[]) { 
             new test();  
         public test(){
              setSize(500, 500);
              Toolkit tk=Toolkit.getDefaultToolkit();
              Dimension d=tk.getScreenSize();
              setLocation(d.width/2-this.getWidth()/2, d.height/2-this.getHeight()/2);
              myObj();
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setVisible(true);
        JMenuBar menubar=new JMenuBar();
        JMenu file=new JMenu("File");
           JMenuItem option1=new JMenuItem("JOptionPane1");
           JMenuItem exit=new JMenuItem("Exit");
        JDesktopPane deskPane=new JDesktopPane();
        private void myObj(){
            option1.addActionListener(this);
            exit.addActionListener(this);
            file.add(option1);
            file.add(exit);
            menubar.add(file);
            setJMenuBar(menubar);
            getContentPane().add(deskPane);
        public void actionPerformed(ActionEvent e){
            Object source=e.getSource();
            if(source==option1){
                JInternalFrame inFrame=new JInternalFrame("Internal Frame", true, true, true, true);
                inFrame.setSize(300, 300);
                inFrame.show();
                inFrame.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
                deskPane.add(inFrame);
            else if(source==exit){
               System.exit(0);

Maybe you are looking for

  • Why does quit safari stay grey

    why can't i quit safari

  • Help! - Xserve running Mac OS X 10.6 Server keep hanging!

    I have a situation here where the Xserve I set up running Mac OS X 10.6 Server keeps hanging after a while. I have re-installed from the scratch thinking it was the third party software I used in importing users and groups but the problem is still th

  • M35X - fan start but the unit shuts down after just 3 sec

    Hi, i have a Toshiba M35X and when i press ON it starts but in 2 or 3 seconds it shuts off.... i already changed the memory and processor, but nothing..... sometimes the main chipset harms sometimes not, the processor idem.... I thank to anyone helps

  • Crash when clicking on edit menu

    Hi, on a customers computer, adobe reader crashes when clicking on the edit menu (german menu "Bearbeiten"). It doesn't matter if a pdf is open or not. Uninstalling and reinstalling did not help. What can I do? Thanks alot, Fabian

  • Need help, What to do when EIS unavailable?

    Hi all, Does anyone know how to implement the following behaviour? : I am doing a WLI project which requires integration of sap and siebel and I want to implement the following behaviour : ü Independence / asynchronous. The Siebel and SAP application