• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 680
  • Last Modified:

JInternalFrame components not shown

Hi!

I've created a JFrame as main program. Into it I created a JDesktopPane which will contain JInternalFrames acting like Dialogs. My problem is when I try to add components like JPanel, JLabel or others into JInternalFrames, because they are not shown, not even using setVisible or updateUI(). I need help. Here a piece of code:

JDesktopPane m_pnlDeskTop = new JDesktopPane();

m_internalDialog = new JInternalFrame("Titulo Dialogo");
m_internalDialog.setClosable(false);
m_internalDialog.setMaximizable(false);
m_internalDialog.setIconifiable(false);
m_internalDialog.setResizable(true);
m_internalDialog.setBounds(50, 50, 400, 300);
m_internalDialog.getContentPane().setLayout(null);
                  
try {
    m_internalDialog.setSelected(true);
} catch (java.beans.PropertyVetoException e2) {
}                   
                  
m_internalDialog.show();

m_pnlDeskTop.add(m_internalDialog);

JPanel pnl = new JPanel();
pnl.setLayout(null);
Rectangle rect = new Rectangle(1, 1, 100, 70);
pnl.setBounds(rect);
pnl.setVisible(true);
m_internalDialog.getContentPane().add(pnl);

JLabel lbl = new JLabel();
lbl.setBounds(new Rectangle(1, 1, 20, 16));
lbl.setVerticalTextPosition(javax.swing.JLabel.CENTER);
lbl.setVisible(true);
m_internalDialog.getContentPane().add(lbl);

m_internalDialog.updateUI();

thanks!
0
accarvajal
Asked:
accarvajal
  • 2
  • 2
1 Solution
 
dextCommented:
give you some codes.................

public class SimpleInternalFrame extends Frame {
    JButton openButton, macButton, javaButton, motifButton, winButton;
    JLayeredPane desktop;
    JInternalFrame internalFrame = null;

    public SimpleInternalFrame() {
        super("Internal Frame Demo");
        setSize(500, 400);
        openButton = new JButton("Open");
        macButton = new JButton("Mac");
        javaButton = new JButton("Metal");
        motifButton = new JButton("Motif");
        winButton = new JButton("Windows");
        Panel p = new Panel();
        p.add(openButton);
        p.add(macButton);
        p.add(javaButton);
        p.add(motifButton);
        p.add(winButton);
        setLayout(new BorderLayout());
        add(p, BorderLayout.SOUTH);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

        openButton.addActionListener(new OpenListener());
        LnfListener lnfListener = new LnfListener(this);
        macButton.addActionListener(lnfListener);
        javaButton.addActionListener(lnfListener);
        motifButton.addActionListener(lnfListener);
        winButton.addActionListener(lnfListener);

        desktop = new JDesktopPane();
        desktop.setOpaque(true);
        add(desktop, BorderLayout.CENTER);
        setResizable(false);

    }

    class OpenListener implements ActionListener {
        public void actionPerformed(ActionEvent event) {
            if ((internalFrame == null) || (internalFrame.isClosed())) {
                int i;
                internalFrame = new JInternalFrame("Internal Frame", false, true, false, true);
                internalFrame.setBounds(50, 50, 200, 100);
                desktop.add(internalFrame, new Integer(1));
                internalFrame.setVisible(true);
            }
        }
    }

    public static void main(String[] args) {
        JFrame.setDefaultLookAndFeelDecorated(true);
        JDialog.setDefaultLookAndFeelDecorated(true);
        (new SimpleInternalFrame()).setVisible(true);
    }

}
0
 
dextCommented:
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;

/**
 * User: Administrator
 * Date: 2005-3-24
 * Time: 20:19:25
 */
class LnfListener implements ActionListener {
    Frame frame;

    public LnfListener(Frame f) {
        frame = f;
    }

    public void actionPerformed(ActionEvent e) {
        String lnfName = null;

        if (e.getActionCommand().equals("Mac")) {
            lnfName = "com.apple.mrj.swing.MacLookAndFeel";
        } else if (e.getActionCommand().equals("Metal")) {
            lnfName = "javax.swing.plaf.metal.MetalLookAndFeel";
        } else if (e.getActionCommand().equals("Motif")) {
            lnfName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
        } else if (e.getActionCommand().equals("Windows")) {
            lnfName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
        } else {
            System.out.println("Error - " + e.getActionCommand());
            return;
        }
        try {
            UIManager.setLookAndFeel(lnfName);
            SwingUtilities.updateComponentTreeUI(frame);
        } catch (ClassNotFoundException e1) {
            e1.printStackTrace();
        } catch (InstantiationException e1) {
            e1.printStackTrace();
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        } catch (UnsupportedLookAndFeelException e1) {
            e1.printStackTrace();
        }
    }
}
0
 
CEHJCommented:
Your panel is there - you just can't see it. If you do

pnl.setBackground(Color.red);

you willl. As for the label, that is hidden by the panel. If you want to see it, you need to add the label to the panel:

//m_internalDialog.getContentPane().add(lbl);
lbl.setOpaque(true);
pnl.add(lbl);
0
 
accarvajalAuthor Commented:
Thanks CEHJ, that is!
0
 
CEHJCommented:
:-)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now