JinternalFrame and setIcon?
Hey guys and gals,
Quick question,
Not sure if this is the correct way to implement this but, im using 5 different internal frames with my JDesktopPane.
However i would like the initial state of the jinternalframes to be icon's not full sized windows. All of these frames are singletons and in their respective self instantiated constructors i specify
//super(name,resizable, closable, maximizable, iconifiable)
super("Accounts Receivables", true, false, true, true);
//lets make the internalframe a
//little smaller than the desktop
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setSize(new Dimension((int)(screenSize.width * 0.65),
(int)(screenSize.height * 0.65)));
setVisible(true);
try{
setIcon(true);
}catch(PropertyVetoException e){
...
}
However the frame is still at its default size, i created another method to see if this method actually works. I created a listener in the desktoppane which calls the jinternalframe.setIcon() with true or false depending on which event i activate and the window does iconify and de-iconify.
However i need them to be icons initially,
Any thoughts or advice would be appreciated.
thanks,
Steven
[1300 byte] By [
m3the01a] at [2007-11-27 8:46:26]

# 1
Here is a sample that creates internal frames, and they show up initially iconified.
I'm not sure how this is different from your code; you didn't provide a complete example showing the behavior. Hopefully this is enough to get you in the right direction.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
public class BasicJInternalFrameExample extends JFrame implements ActionListener {
private JDesktopPane desktop;
private int counter = 1;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new BasicJInternalFrameExample();
}
});
}
public BasicJInternalFrameExample() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
desktop = new JDesktopPane();
Container content = getContentPane();
JButton btnAdd = new JButton("Add Internal Frame");
btnAdd.addActionListener(this);
JMenuBar menu = new JMenuBar();
menu.add(btnAdd);
setJMenuBar(menu);
content.setLayout(new BorderLayout());
content.add(desktop, BorderLayout.CENTER);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
setSize((int) (screen.getWidth() * 0.75), (int) (screen.getHeight() * 0.75));
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
JInternalFrame iFrame = new JInternalFrame("Internal Frame " + counter++, true, true, true, true);
iFrame.pack();
iFrame.setSize(new Dimension(300, 100));
iFrame.setVisible(true);
desktop.add(iFrame);
desktop.moveToFront(iFrame);
try {
iFrame.setIcon(true);
} catch (PropertyVetoException e1) {
e1.printStackTrace();
}
}
}
# 2
Hey thank u very much for the reply!
However, my code also works when i want to create jinternalframes on the fly while in the application. However on initial load of the main desktop, java mainclass, is there a way if say u have 5 jinternalframes for them all to be in icon format?
Your code like mine works perfectly when say i create a listener which creates frames on the fly as icons once the application is already running. However lets say we initially have 5 jinternalframes and we invoke the application, can we get them to show up as icons?
I found a work around if there isnt a built in method to accomplish this, i created a simple button that invokes the setVisible() routine for each of the jinternalframe however i would like to use as much built in functionality as possible.
If its still not clear what im trying to accomplish let me know,
thanks again
# 3
PS as another note, when i attempt to accomplish the setIcon(true) in the constructor of the jinternalframe. The window is the large non minimized window under initial load of the application, java mainapp. When i perform an action connected with setIcon(true), i get no response from the JinternalFrame, expecting a icon here. I must first perform an action connected to setIcon(false), than an action connected with setIcon(true) to get the window minimized.
However if i leave the setIcon(true) out of the initial constructor of the singleton jinternalframe, the action connected with setIcon(true) minimizes and creates the correct icon without the need for the action connected with setIcon(false) as earlier mentioned in the previous example.
Basically what i think is going on is,
When the constructor calls setIcon(true), it sets a internal flag to true call it isIcon = true;
Now in reality, the window is not iconified under initial load however the flag isIcon is actually set to true.
Now remember the window is in its full screen mode and not iconified, i call an action associated with setIcon(true). It than invokes a inherited method of some sort which checks isIcon first. If its true than do nothing if its false make the window an icon and set isIcon = true.
Basically what i think is happening is, isIcon is getting set to true when setIcon(true) is getting called in the constructor. However its not true because the JinternalFrame is the large window. When i attempt a call to setIcon(true), remember the window is not iconified, nothing happens because isIcon is set to true(assumption). I need to first call setIcon(false), which sets isIcon to false, then call setIcon(true).
This behavior is unexpected, could anyone verify?
Ive tested under mac osX and suse 10.3. Thats all i have access to.
thanks
# 4
A slight variation on my earlier code. Creates 5 internal frames, all iconified at application start.
import javax.swing.*;
import java.awt.*;
import java.beans.PropertyVetoException;
public class JInternalFrameIconified extends JFrame {
private JDesktopPane desktop;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new JInternalFrameIconified();
}
});
}
public JInternalFrameIconified() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
desktop = new JDesktopPane();
Container content = getContentPane();
content.setLayout(new BorderLayout());
content.add(desktop, BorderLayout.CENTER);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
setSize((int) (screen.getWidth() * 0.75), (int) (screen.getHeight() * 0.75));
for (int i = 1; i <= 5; i++) {
addInternalFrame(i);
}
setVisible(true);
}
private void addInternalFrame(int i) {
JInternalFrame iFrame = new JInternalFrame("Internal Frame " + i, true, true, true, true);
iFrame.pack();
iFrame.setSize(new Dimension(300, 100));
iFrame.setVisible(true);
desktop.add(iFrame);
desktop.moveToFront(iFrame);
try {
iFrame.setIcon(true);
} catch (PropertyVetoException e) {
e.printStackTrace();
}
}
}
# 5
What OS are u using? I know java should be standard but i have seen little difference.thanks,
# 6
> What OS are u using? Win XP 2002 SP 2, Java SE 1.6.0_01.
# 7
Yeah i ran the code under OSX and Suse 10.3 and it doesnt work.It creates a icon try but with nothing in it.
# 8
This is underjava version "1.5.0_07"Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-164)Java HotSpot(TM) Client VM (build 1.5.0_07-87, mixed mode, sharing)
# 9
> Yeah i ran the code under OSX and Suse 10.3 and it> doesnt work.Well, unfortunately that's the limit of the help that I can provide - I only have Windows machines at my disposal.
# 10
No problem,I greatly appreciate all your help and time!thanks
# 11
Is there a way to specify a default icon to use? It seems like there is not default picture for the system to use, i see there is a setdesktopicon but its suggested not to use with swing.