2 Replies Latest reply: Aug 29, 2012 3:09 PM by 955780 RSS

    JDesktopPane Trials

      well, im trying to learn how to use the JDesktopPane and i found some examples on the web, and i cant get it to work "properly"

      This example is just a menu with an item menu that adds an internal frame, the internal frame adds a Textfield to itself and here is the part that i don't understand, for some reason the textfield isnt visible.

      If i run debug, i can notice in a GUI snapshot that the frame is actually being created but i cant see it. here is the code.

       * To change this template, choose Tools | Templates
       * and open the template in the editor.
      package src;
       * @author pato
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.awt.BorderLayout;
      import java.awt.Container;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import javax.swing.JDesktopPane;
      import javax.swing.JFrame;
      import javax.swing.JInternalFrame;
      import javax.swing.JLabel;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JMenuItem;
      import javax.swing.JPanel;
      public class Main extends JFrame {
        public Main() {
          JMenuBar bar = new JMenuBar();
          JMenu addMenu;
              addMenu = new JMenu("Add");
          JMenuItem newFrame;
              newFrame = new JMenuItem("Internal Frame");
          final JDesktopPane theDesktop = new JDesktopPane();
          newFrame.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              JInternalFrame frame;
                  frame = new JInternalFrame("Internal Frame", true, true, true, true);
              Container c = frame.getContentPane();
              MyJPanel panel = new MyJPanel();
              c.add(panel, BorderLayout.CENTER);
          setSize(500, 400);
        public static void main(String args[]) {
          Main app = new Main();
      class MyJPanel extends JPanel {
        public MyJPanel() {
          JTextField label=new JTextField("Hello World");
          label.setBackground(Color.CYAN); //this is the same as a JLabel
      THX in advance