Link to home
Start Free TrialLog in
Avatar of accarvajal
accarvajal

asked on

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!
Avatar of dext
dext
Flag of United States of America image

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);
    }

}
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();
        }
    }
}
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of accarvajal
accarvajal

ASKER

Thanks CEHJ, that is!
:-)