4 Replies Latest reply: Oct 7, 2004 10:15 AM by 807587 RSS

    JinternalFrame border disappear behind other internal frame's Panels

    807587
      Hi
      I have a simble MDI application with 2 internal frames.
      internal frame 1 contains a black panel
      internal frame 2 is empty.

      my problem is :
      (internal frame 2 )'s Border disappear behind the panel in (internal frame 1).
      how could i solve this??

      here is my code :

      ****************************************************************

      import java.awt.*;
      import java.awt.event.*;

      import javax.swing.*;

      public class DesktopExample extends JFrame
      {     
      public static void main(String[] args)
      {          
      JFrame.setDefaultLookAndFeelDecorated(true);
      final JDesktopPane desktop = new JDesktopPane();
      desktop.setPreferredSize(new Dimension(600, 400));
      JMenuBar mb = new JMenuBar();          
      JMenu menu = new JMenu("File");          
      JMenuItem item = new JMenuItem("Internal frame 1");     
      JMenuItem item2 = new JMenuItem("Internal Frame 2");
      item.addActionListener(new ActionListener()
      {     
      public void actionPerformed(ActionEvent evt)
      {          
      JInternalFrame fr = new JInternalFrame("internal", true, true, true, true);     
      Panel panel = new Panel();
      panel.setSize(100,100);
      panel.setBackground(Color.black);
      fr.getContentPane().add(panel);
      fr.setBounds(100, 100, 300, 200);
      fr.show();
      desktop.add(fr);          
      fr.setVisible(true);     
      }
      }
      );
      item2.addActionListener(new ActionListener()
      {     
      public void actionPerformed(ActionEvent evt)
      {          
      JInternalFrame fr = new JInternalFrame("internal", true, true, true, true);     
      fr.setBounds(200, 200, 300, 200);
      desktop.add(fr);          
      fr.setVisible(true);     
      }
      }
      );
      menu.add(item);
      menu.add(item2);
      mb.add(menu);          
      JFrame f = new JFrame("DesktopExample");     
      f.setJMenuBar(mb);     
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     
      f.getContentPane().add(desktop);     
      f.pack();          
      //f.setLocationRelativeTo(null);     
      f.setVisible(true);     
      }
      }




      *************************************************

      Thank you.
        • 1. Re: JinternalFrame border disappear behind other internal frame's Panels
          800382
          Didn't your mother ever tell you not to mix AWT and Swing components?
          http://java.sun.com/products/jfc/tsc/articles/mixing/index.html
          • 2. Re: JinternalFrame border disappear behind other internal frame's Panels
            807587
            :) Realy, she did not.

            any way thank you for your reply
            but now my problem goes to what is the opposit Swing classes for the following AWT Classes?
            ----> Canvas ???

            what is the opposit for (Canvas) in swings ???
            thank you again :)
            • 3. Re: JinternalFrame border disappear behind other internal frame's Panels
              807587
              You can treat a JPanel much the same as a Canvas, you just need to override the paintComponent methods.

              nes
              • 4. Re: JinternalFrame border disappear behind other internal frame's Panels
                807587
                may you please how could I do this in the following code?



                import java.awt.*;
                import javax.swing.*;

                public class MessageArea extends Canvas
                {

                public MessageArea()
                {
                normalMode = true;
                }

                public MessageArea(int size)
                {
                normalMode = true;
                label = "";
                this.size = size;
                init();
                }

                void init()
                {
                bgColor = new Color(155, 175, 202);
                textColor = Color.black;
                Font font = new Font("Dialog", 1, 12);
                setFont(font);
                FontMetrics fm = getFontMetrics(getFont());
                xMargin = fm.charWidth('0');
                yMargin = 2;
                textOffset = new Point(xMargin, fm.getAscent() + yMargin);
                width = xMargin * size + 2 * xMargin;
                height = fm.getAscent() + fm.getDescent() + 2 * yMargin;
                }

                public void setBGColor(Color bgColor)
                {
                this.bgColor = bgColor;
                }

                public void setTextColor(Color textColor)
                {
                this.textColor = textColor;
                }

                public void setLabel(String label)
                {
                this.label = label;
                if(isVisible())
                repaint();
                }

                public void setLabel(String label, Color textColor)
                {
                this.label = label;
                this.textColor = textColor;
                if(isVisible())
                repaint();
                }

                public void paint(Graphics g)
                {
                setBackground(bgColor);
                g.setColor(textColor);
                g.drawString(label, textOffset.x, textOffset.y);
                }

                public Dimension getPreferredSize()
                {
                return new Dimension(width, height);
                }

                public Dimension getMinimumSize()
                {
                return new Dimension(width, height);
                }

                String label;
                int width;
                int height;
                Point textOffset;
                Color bgColor;
                Color textColor;
                int xMargin;
                int yMargin;
                boolean normalMode;
                int size;
                }