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.setClosab le(false);
m_internalDialog.setMaximi zable(fals e);
m_internalDialog.setIconif iable(fals e);
m_internalDialog.setResiza ble(true);
m_internalDialog.setBounds (50, 50, 400, 300);
m_internalDialog.getConten tPane().se tLayout(nu ll);
try {
m_internalDialog.setSelect ed(true);
} catch (java.beans.PropertyVetoEx ception e2) {
}
m_internalDialog.show();
m_pnlDeskTop.add(m_interna lDialog);
JPanel pnl = new JPanel();
pnl.setLayout(null);
Rectangle rect = new Rectangle(1, 1, 100, 70);
pnl.setBounds(rect);
pnl.setVisible(true);
m_internalDialog.getConten tPane().ad d(pnl);
JLabel lbl = new JLabel();
lbl.setBounds(new Rectangle(1, 1, 20, 16));
lbl.setVerticalTextPositio n(javax.sw ing.JLabel .CENTER);
lbl.setVisible(true);
m_internalDialog.getConten tPane().ad d(lbl);
m_internalDialog.updateUI( );
thanks!
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.setClosab
m_internalDialog.setMaximi
m_internalDialog.setIconif
m_internalDialog.setResiza
m_internalDialog.setBounds
m_internalDialog.getConten
try {
m_internalDialog.setSelect
} catch (java.beans.PropertyVetoEx
}
m_internalDialog.show();
m_pnlDeskTop.add(m_interna
JPanel pnl = new JPanel();
pnl.setLayout(null);
Rectangle rect = new Rectangle(1, 1, 100, 70);
pnl.setBounds(rect);
pnl.setVisible(true);
m_internalDialog.getConten
JLabel lbl = new JLabel();
lbl.setBounds(new Rectangle(1, 1, 20, 16));
lbl.setVerticalTextPositio
lbl.setVisible(true);
m_internalDialog.getConten
m_internalDialog.updateUI(
thanks!
import javax.swing.*;
import java.awt.event.ActionListe ner;
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(ActionEven t e) {
String lnfName = null;
if (e.getActionCommand().equa ls("Mac")) {
lnfName = "com.apple.mrj.swing.MacLo okAndFeel" ;
} else if (e.getActionCommand().equa ls("Metal" )) {
lnfName = "javax.swing.plaf.metal.Me talLookAnd Feel";
} else if (e.getActionCommand().equa ls("Motif" )) {
lnfName = "com.sun.java.swing.plaf.m otif.Motif LookAndFee l";
} else if (e.getActionCommand().equa ls("Window s")) {
lnfName = "com.sun.java.swing.plaf.w indows.Win dowsLookAn dFeel";
} else {
System.out.println("Error - " + e.getActionCommand());
return;
}
try {
UIManager.setLookAndFeel(l nfName);
SwingUtilities.updateCompo nentTreeUI (frame);
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (UnsupportedLookAndFeelExc eption e1) {
e1.printStackTrace();
}
}
}
import java.awt.event.ActionListe
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(ActionEven
String lnfName = null;
if (e.getActionCommand().equa
lnfName = "com.apple.mrj.swing.MacLo
} else if (e.getActionCommand().equa
lnfName = "javax.swing.plaf.metal.Me
} else if (e.getActionCommand().equa
lnfName = "com.sun.java.swing.plaf.m
} else if (e.getActionCommand().equa
lnfName = "com.sun.java.swing.plaf.w
} else {
System.out.println("Error - " + e.getActionCommand());
return;
}
try {
UIManager.setLookAndFeel(l
SwingUtilities.updateCompo
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (UnsupportedLookAndFeelExc
e1.printStackTrace();
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks CEHJ, that is!
:-)
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.addActionListen
LnfListener lnfListener = new LnfListener(this);
macButton.addActionListene
javaButton.addActionListen
motifButton.addActionListe
winButton.addActionListene
desktop = new JDesktopPane();
desktop.setOpaque(true);
add(desktop, BorderLayout.CENTER);
setResizable(false);
}
class OpenListener implements ActionListener {
public void actionPerformed(ActionEven
if ((internalFrame == null) || (internalFrame.isClosed())
int i;
internalFrame = new JInternalFrame("Internal Frame", false, true, false, true);
internalFrame.setBounds(50
desktop.add(internalFrame,
internalFrame.setVisible(t
}
}
}
public static void main(String[] args) {
JFrame.setDefaultLookAndFe
JDialog.setDefaultLookAndF
(new SimpleInternalFrame()).set
}
}