JinternalFrame border disappear behind other internal frame's Panels

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.

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

Similar Messages

  • How can I use internal frames with buttons to call others internal frames?

    Hello.
    I'm building a MDI-application using JFrames and several JInternalFrames, but I have problems.
    A JFrame has JMenuBar with JMenu and JMenuItem. One of these, call the first JInternal that has its interface. In this interface has a button that call other type (a class extension of JInternalFrame) JInternalFrame.
    When I clicked button happen a exception (java.lang.NullPointer).
    What happening?
    Help me, please.

    What i usually do is to give my desktop to my internal frames. So within the internalframe, you can use your desktop and add other internal frames to it.
    The code should look something like the following.
    desktop = your JDesktopPane
    MyInternalFrame = an InternalFrame
    AnotherMyInternalFrame = another InternalFrame
    public class MyInternalFrame extends JInternalFrame implements ActionListener
      private JButton jb = new JButton("Launch");
      private JLayeredPane desktop = null;
      public MyInternalFrame(JLayeredPane desktop)
        this.desktop = desktop;
        getContentPane().add(jb);
        jb.addActionListener(this);
      public void actionPerformed(ActionEvent ae)
        if (ae.getSource() == jb)
          desktop.add(new AnotherMyInternalFrame(desktop),JLayeredPane.DEFAULT_LAYER);
    }

  • Scrolling main content in an AP Div disappearing behind other AP Divs...?

    Newbie here, using CS3. No CSS power user (yet!)--general concepts, yes, but not much practice. Meanwhile two recent CS3 classes, several books, and a concerted search through online forums have failed to point me toward a fix for this prob. Any help greatly appreciated.
    Prob statement: In design view the core content of my pages disappears behind my footer and a secondary box, both AP Divs, so that I cannot see or edit anything beyond the bottom edge of the core-content AP Div. Overflow for that AP Div is set to scroll. The "obscured" content shows up only as an outlined shape extending past the footer etc. (and I can see some of the obscured text "through" the footer). Down arrow doesn't get me there: it just scoots down the outlined-but-obscured section. Doubleclicking highlights everything that's obscured so that I can see the relative shapes of the paragraphs, but doesn't expose the content. This seemed to start the first time I set the content div to scroll any overflow. I've changed it back/forth since; no joy.
    Rendered in IE or Firefox, all the pages with all their varying content lengths look fine. Scrollbar works great. It's just that in order to edit or compose further, I have to copy everything into Notepad or something, work there, and then paste it back into DW. Definitely non-optimum, though: can't format or add hyperlinks to the content.
    I'm using AP Divs, with scroll on in the "content" AP Div, because I couldn't figure out how to create a template where the footer would slide down the page in response to varying amounts of content. Started out with a table to handle all this, but an instructor recommended AP Divs so I went that way. I'd like to resolve this, rather than just go back to using tables while leaving this AP Div oddness a mystery.
    The footer is full of a Spry tabbed panels giving my legal/green/design statements and other small bits of info. The secondary box is an AP Div called "quotations" and is for friendly little bits of cute/clever nonsense at the bottom of each page.
    Tried a number of different settings so far and by now I've probably truly messed things up. Can anyone suggest a fix?
    The code for the template file seems long, so my apologies. However, the content type isn't allowed for attachments so I've pasted it in below.
    Much appreciation!
    =================================
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style type="text/css">
    <!--
    body {
        background-color: #003300;
    #LeftSidebar {
        position:absolute;
        width:80px;
        height:697px;
        z-index:1;
        background-image: url(../Images/BG.jpg);
        top: 20px;
    #Banner {
        position:absolute;
        width:360px;
        height:187px;
        z-index:2;
        left: 100px;
        top: 20px;
        background-color: #6384EF;
    #BannerPhone {
        position:absolute;
        width:265px;
        height:187px;
        z-index:3;
        left: 470px;
        top: 20px;
        font-family: Georgia, "Times New Roman", Times, serif;
        font-size: x-large;
        font-variant: normal;
        color: #E4D9A8;
    #NavBar {
        position:absolute;
        width:636px;
        height:35px;
        z-index:4;
        left: 100px;
        top: 219px;
        padding-top: 3px;
        padding-right: 0px;
        padding-bottom: 0px;
        padding-left: 5px;
        background-color: #E4D9A8;
        border-top-color: #E4D9A8;
        border-right-color: #E4D9A8;
        border-bottom-color: #E4D9A8;
        border-left-color: #E4D9A8;
    #Heading {
        position:absolute;
        left:100px;
        top:254px;
        width:636px;
        height:42px;
        z-index:8;
        font-family: Verdana, Arial, Helvetica, sans-serif;
        font-size: medium;
        font-weight: bold;
        color: #003300;
        background-color: #E4D9A8;
        text-indent: 5px;
        padding-top: 5px;
        padding-right: 0px;
        padding-bottom: 0px;
        padding-left: 5px;
        border-top-color: #E4D9A8;
        border-right-color: #E4D9A8;
        border-bottom-color: #E4D9A8;
        border-left-color: #E4D9A8;
        vertical-align: bottom;
    #Content {
        position:absolute;
        width:636px;
        height:315px;
        z-index:9;
        left: 100px;
        top: 296px;
        font-family: Verdana, Arial, Helvetica, sans-serif;
        font-size: small;
        color: #003300;
        background-color: #E4D9A8;
        overflow: scroll;
        padding-top: 0px;
        padding-right: 0px;
        padding-bottom: 0px;
        padding-left: 5px;
    #Footer {
        position:absolute;
        width:560px;
        height:50px;
        z-index:-1;
        left: 133px;
        top: 670px;
        background-color: #E4D9A8;
    #Quotation {
        position:absolute;
        width:636px;
        height:40px;
        z-index:0;
        left: 101px;
        top: 621px;
        font-family: Georgia, "Times New Roman", Times, serif;
        font-size: x-small;
        font-style: italic;
        color: #E4D9A8;
        text-indent: 5px;
        padding-top: 0px;
        padding-right: 0px;
        padding-bottom: 0px;
        padding-left: 5px;
        background-color: #003300;
    -->
    </style>
    <script src="../SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
    <link href="../SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
    <!--
    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    function MM_nbGroup(event, grpName) { //v6.0
      var i,img,nbArr,args=MM_nbGroup.arguments;
      if (event == "init" && args.length > 2) {
        if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
          img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
          if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
          nbArr[nbArr.length] = img;
          for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
            if (!img.MM_up) img.MM_up = img.src;
            img.src = img.MM_dn = args[i+1];
            nbArr[nbArr.length] = img;
      } else if (event == "over") {
        document.MM_nbOver = nbArr = new Array();
        for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
          if (!img.MM_up) img.MM_up = img.src;
          img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
          nbArr[nbArr.length] = img;
      } else if (event == "out" ) {
        for (i=0; i < document.MM_nbOver.length; i++) {
          img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
      } else if (event == "down") {
        nbArr = document[grpName];
        if (nbArr)
          for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
        document[grpName] = nbArr = new Array();
        for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
          if (!img.MM_up) img.MM_up = img.src;
          img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
          nbArr[nbArr.length] = img;
    //-->
    </script>
    <!-- TemplateParam name="Content2" type="boolean" value="true" -->
    <style type="text/css">
    <!--
    a:link {
        color: #003300;
    a:visited {
        color: #336666;
    a:hover {
        color: #009933;
    a:active {
        color: #990033;
    -->
    </style>
    <meta name="Description" content="Skyway Consulting: taking your information to a higher level! We do information design: planning, writing, editing, and indexing your user documentation. We also design websites, website graphics, print layouts, and logos. Basically, we want to be your source for the way your organization interfaces with the world. " />
    </head>
    <body onload="MM_preloadImages('../Images/Button_WebDesignOver.gif','../Images/Button_UserDocsO ver.gif','../Images/Button_LogoDesignOver.gif','../Images/Button_PrintLayoutOver.gif','../ Images/Button_ITSvcsOver.gif','../Images/Button_Home.gif','../Images/Button_HomeOver.gif', '../Images/Button_WebDesign.gif','../Images/Button_UserDocs.gif','../Images/Button_ITSvcs. gif','../Images/Button_LogoDesign.gif','../Images/Button_AboutUs.gif','../Images/Button_Co ntact.gif','../Images/Button_AboutUsOver.gif')">
    <div id="LeftSidebar"></div>
    <div id="Banner">
      <div align="center"><img src="../Images/Banner.gif" alt="Skyway Consulting" width="335" height="184" /></div>
    </div>
    <div id="BannerPhone">
      <p align="center">Taking your information to a higher level.</p>
      <p align="center">530.965.2624</p>
      <p align="center"><img src="../Images/email_Info.gif" alt="Address" width="203" height="23" /></p>
    </div>
    <div id="NavBar">
      <table border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td><a href="../index.html" target="_top" onclick="MM_nbGroup('down','group1','Home','../Images/Button_HomeOver.gif',1)" onmouseover="MM_nbGroup('over','Home','../Images/Button_HomeOver.gif','',1)" onmouseout="MM_nbGroup('out')"><img src="../Images/Button_Home.gif" alt="Skyway Consulting Homepage" name="Home" border="0" id="Home" onload="" /></a></td>
          <td><a href="../webdesign.html" target="_top" onclick="MM_nbGroup('down','group1','WebsiteDesign','../Images/Button_WebDesignOver.gif', 1)" onmouseover="MM_nbGroup('over','WebsiteDesign','../Images/Button_WebDesignOver.gif','',1) " onmouseout="MM_nbGroup('out')"><img src="../Images/Button_WebDesign.gif" alt="Website Design Services" name="WebsiteDesign" width="106" height="30" border="0" id="WebsiteDesign" onload="" /></a></td>
          <td><a href="javascript:;" target="_top" onclick="MM_nbGroup('down','group1','UserDoc','../Images/Button_UserDocsOver.gif',1)" onmouseover="MM_nbGroup('over','UserDoc','../Images/Button_UserDocsOver.gif','',1)" onmouseout="MM_nbGroup('out')"><img src="../Images/Button_UserDocs.gif" alt="User Documentation Services" name="UserDoc" width="106" height="30" border="0" id="UserDoc" onload="" /></a></td>
          <td><a href="../it_svcs.html" target="_top" onclick="MM_nbGroup('down','group1','ITServices','../Images/Button_ITSvcsOver.gif',1)" onmouseover="MM_nbGroup('over','ITServices','../Images/Button_ITSvcsOver.gif','',1)" onmouseout="MM_nbGroup('out')"><img src="../Images/Button_ITSvcs.gif" alt="IT Services" name="ITServices" width="106" height="30" border="0" id="ITServices" onload="" /></a></td>
          <td><a href="javascript:;" target="_top" onclick="MM_nbGroup('down','group1','LogoDesign','../Images/Button_LogoDesignOver.gif',1) " onmouseover="MM_nbGroup('over','LogoDesign','../Images/Button_LogoDesignOver.gif','',1)" onmouseout="MM_nbGroup('out')"><img src="../Images/Button_LogoDesign.gif" alt="Logo Design Services" name="LogoDesign" width="106" height="30" border="0" id="LogoDesign" onload="" /></a></td>
          <td><a href="../about.html" target="_top" onclick="MM_nbGroup('down','group1','AboutUs','../Images/Button_AboutUsOver.gif',1)" onmouseover="MM_nbGroup('over','AboutUs','../Images/Button_AboutUsOver.gif','',1)" onmouseout="MM_nbGroup('out')"><img src="../Images/Button_AboutUs.gif" alt="AboutUs" name="AboutUs" border="0" id="Contact" onload="" /></a></td>
        </tr>
      </table>
    </div>
    <div id="Content"><!-- TemplateBeginEditable name="Content" -->
      <p>Content</p>
      <!-- TemplateEndEditable --></div>
    <div id="Footer">
      <div id="TabbedPanels1" class="TabbedPanels">
        <ul class="TabbedPanelsTabGroup">
          <li class="TabbedPanelsTab" tabindex="0">Info</li>
          <li class="TabbedPanelsTab" tabindex="0">Legal</li>
          <li class="TabbedPanelsTab" tabindex="0">Privacy Policy</li>
          <li class="TabbedPanelsTab" tabindex="0">Green Statement</li>
          <li class="TabbedPanelsTab" tabindex="0">Design Credit</li>
          <li class="TabbedPanelsTab" tabindex="0">Webmaster</li>
        </ul>
        <div class="TabbedPanelsContentGroup">
          <div class="TabbedPanelsContent">Click for information on these topics.</div>
          <div class="TabbedPanelsContent">(c) 2009 Skyway Consulting. All content, including photographic content, is owned by Skyway Consulting. You may not copy, reproduce, modify, or publicly display, perform, distribute, or otherwise use the content provided on this site in any way for any public or commercial purpose. Skyway Consulting will not work on websites involving objectionable material, including but not limited to pornography, hatred, intolerance, or animal abuse. Our management staff's decision on what constitutes &quot;objectionable material&quot; is final. </div>
          <div class="TabbedPanelsContent">We recognize that your privacy is important. This privacy policy applies to all of our services and website pages. We do not set cookies. We do not sell or otherwise seek to profit from the contact information you provide, although we may preserve some information for use by Skyway Consulting. If you have questions about this privacy policy, please [link]contact us.</div>
          <div class="TabbedPanelsContent">Skyway Consulting is an American home-based business that makes every effort to conserve, reduce, reuse, and recycle.</div>
          <div class="TabbedPanelsContent">
            <p>Page design by Skyway Consulting. (Of course!)</p>
            <p>Tiling forest graphic at left by the talented Silvia Hartmann, <a href="http://silviahartmann.com/">http://silviahartmann.com/</a>. (Thank you, Silvia!)</p>
          </div>
          <div class="TabbedPanelsContent">Page problems? Contact <img src="../Images/email_Webmaster.gif" alt="Webmaster e-dress" width="177" height="18" align="absmiddle" /></div>
        </div>
      </div>
    </div>
    <div id="Quotation"><!-- TemplateBeginEditable name="Quotation" -->Quotation<!-- TemplateEndEditable --></div>
    <div id="Heading"><!-- TemplateBeginEditable name="Heading" -->Heading<!-- TemplateEndEditable --></div>
    <div align="center"></div>
    <script type="text/javascript">
    <!--
    var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
    //-->
    </script>
    </body>
    </html>

    I hadn't looked at the code at all. I was relying on the Dreamweaver GUI to correctly guide me to a desired outcome.
    I think that this is not a desirable approach to Dreamweaver, which will write perfect HTML if you let it, but it's too easy to click buttons and apply wizards without regard for the markup consequences, thereby producing a veritable pig's ear of a page.  If you are going to use DW professionally, you will have to become comfortable with code.  That doesn't mean you will have to spend 100% of your time in Code view, but you will definitely need to watch the code as it is formulated.
    I'm not starting from an engineering background.
    Neither did I.  But I did start with a sincere desire to become proficient, and to learn the technology.
    Murray, I get the idea of redoing my template without AP Divs, and will get into that. I don't know what "image swaps and links" mean, though. Would you mind teaching this newbie on this point?
    Not at all.  When you select the "NavBar" feature, you are placing elements and code on your page that were designed in the dark ages of HTML (frames).  Some of the features in the NavBar will only work in a framed page (the down image and the over while down).  The code is antique, invalid, and just wrong to be included.  My suggestion was to forego this and just place your button images on the page (in whatever container you need to use), and apply links to them so that they link to the desired pages.  Then apply swap image behaviors to them to create your rollover effects, one for each button.  The result will be modern code, that has none of the legacy stuff of the navbar, and that will work fine for you.  As you become more familiar with CSS you can investigate even better ways to do such menus (if you want a preview of this, Google "CSS Sprites).  The latter method is usually the only way I do menus anymore.  And even then, I use both text and graphics for accessability and SEO purposes.
    I will say that I like your attitude.  A determination to learn and improve is a winning approach.

  • Working window disappears behind other open windows at random times.

    The window I'm working on keeps popping back behind other open windows at random times (not related to the program I'm using). Is anyone else experiencing this after upgrading to Mavericks?

    This is what happens for one of the active corners for Exposé, if ("all windows") is the upper left corner. Take a look at "System preferences" , Dashboard & Exposé.
    Message was edited by: eddy kestemont

  • Background picture n problem on display other JInternal frame

    beginer;
    this is my code below n i compile it n the picture display correctly, but it seems to hide other internal frame as well, what wrong with my code :(, the problem is been specified between ? symbols
    public class InternalFrameDemo extends JFrame implements ActionListener {
    JDesktopPane desktop;
    public InternalFrameDemo() {
    super("InternalFrameDemo");
    int inset = 50;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(inset, inset,
    screenSize.width - inset*2,
    screenSize.height - inset*2);
    Toolkit kit = Toolkit.getDefaultToolkit();
    Image icon = kit.getImage("ADD.gif");
    setIconImage(icon);
    //Set up the GUI.
    desktop = new JDesktopPane(); //a specialized layered pane
    createFrame(); //create first "window"
    setContentPane(desktop);
    setJMenuBar(createMenuBar());
    //Make dragging a little faster but perhaps uglier.
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    ImageIcon image = new ImageIcon("abc.jpg");
    JLabel background = new JLabel(image);
    background.setBounds(0, 0, image.getIconWidth(), image.getIconHeight());
    getLayeredPane().add(background, new Integer(Integer.MIN_VALUE) );
    JPanel panel = new JPanel();
    panel.setOpaque(false);
    setContentPane( panel );
    protected JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    //Set up the menu item
    return menuBar;
    public void actionPerformed(ActionEvent e) {
    else {
    quit();
    protected void createFrame() {
    Books frame = new Books();
    frame.setVisible(true);
    desktop.add(frame);
    try {
    frame.setSelected(true);
    catch (java.beans.PropertyVetoException e) {}
    protected void quit() {
    System.exit(0);
    public static void main(String[] args) {
    try {
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    catch (Exception e) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Create and set up the window.
    InternalFrameDemo frame = new InternalFrameDemo();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Display the window.
    frame.setVisible(true);
    tanz.

    This might be what you are trying to do:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.plaf.*;
    public class TestInternalFrame extends JFrame
         ImageIcon icon;
         public TestInternalFrame()
              icon = new ImageIcon("????.jpg");
              JDesktopPane desktop = new JDesktopPane()
                 public void paintComponent(Graphics g)
                      Dimension d = getSize();
                      g.drawImage(icon.getImage(), 0, 0, d.width, d.height, null);
              getContentPane().add( desktop );
              final JInternalFrame internal =
                   new JInternalFrame( "Internal Frame", true, true, true, true );
              desktop.add( internal );
              internal.setLocation( 50, 50 );
              internal.setSize( 300, 300 );
              internal.setVisible( true );
         public static void main(String args[])
              TestInternalFrame frame = new TestInternalFrame();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.setSize(400, 400);
              frame.setVisible(true);
    }

  • Checking status of an internal frame

    I am writting an application that uses seperate class file for internal frames. I want to use a Menu Bar that will open the internal frame if it is closed or bring it to the foreground if it is open but behind another internal frame or restore the internal frame if it is minimized.
    I can create the internal frame easy enough with the following (this is the code that I call when the Menu Item is clicked:
    // Create a "SETUP" internal frame
    MyinternalFrame if_Setup = new MyinternalFrame("SETUP");
    // Add it to the desktop
    myDesktop.add(if_Setup);How to I check the condition of my internal frame, if_Setup?

    there are many programmes available in globalleafs.com 's download. they helped me alot. try it.

  • Image icon on internal frame disappearing and re-appearing

    I have just upgraded to jdk 1.4.1-b21 from 1.4.0_01-b03 and have noticed that after adding an Internal Frame to a desktop and moving the mouse over the image icon in the left hand corner the image disappears. The image re-appears again, once I presume, when the desktop and its frames are repainted.
    Is this a bug or has something changed between the two jdk's.
    Thanks.
    Steve.

    Hi,
    I attempted the Disk Utility Repair but it did not work.
    So I disabled the application 'StickyWindows' and this resolved the problem.
    Hope this helps.

  • When I have my Firefox browser running, if I bring up a document from my computer, it appears briefly, then disappears behind the browser. It shows in the taskbar, but won't stay on top until I minimize all other windows.

    When I have my Firefox browser running, if I bring up a document from my computer, it appears briefly, then disappears behind the browser. It shows in the taskbar, but won't stay on top until I minimize all other windows.

    Hi NicoMan,
    According to your description ,we seem to suffer a performance issue here.
    Have you tried to open the task manager to check the system performance  ? Is there any specific process occupied many system resources ?Will the issue occur only with the specific applications ?
    We can try to restart the Windows Explorer process to have a check.
    If it only occurred with the spefcific two applications ,we can try to end the other application processes manually from the task manager to have a check .
    If this is caused by the specific application ,we may need to look for help from the third party support considering they are all the third party applications .
    Best regards
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • Plz help me with the internal frames

    hi,.
    i have design mainframe of my application contain some jinternalframes
    .but these internal frames are not properly working since my mainframe contain borderlayout , mainframe also contain some menubar ,toolbar,jtable .so whenever i call my internalframes these frames just get behind my jtable . whenever i shift the border layout to
    east or west or north the internalframes just get shift inthe given space .actually by default i have border layout as center.when shift my layout to flow layout menubar,toolbar, every thing get shifted , so another problems occur. if iam using flow layout the size of the internalframes remain the same as setted in the code. else in the borderlayout it acqurie the whole of the desktopPane.and no resize code works on it. setsize,setbound,sestpreffredsize,dimension non of these method work.
    thanx for now hope u will slove my problems .

    Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/internalframe.html]How to Use Internal Frames. You add a JDesktopPane to the contentPane and then add the JInternalFrames to the desktop pane.
    If you want to add other components to the GUI then you add them to some other part of the content pane. You don't mix other Swing components and internal frame on the desktop pane.

  • Custom internal frames

    Hello,
    I have written some custom internal frames, along with their UI's, title panes, and desktop icons. Everything seems to work fine when I'm in JBuilder and I use the "run" command, but when I compile the program and run it as a batch file, my internal frames appear as gray boxes that can't be moved or resized.
    package KComponent;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import Theme.*;
    import java.io.*;
    import javax.swing.border.*;
    public class KInternalFrame extends JInternalFrame {
      private JLabel titleLabel;
      private String title;
      public static Color titleColor = Color.white;
      public static Color titleBarColor = Theme.DARK;
      private KButton maximize, minimize, normalize;
      private static final String PATH = "pics" + File.separator;
      public KInternalFrame(String title) {
        super(title, true, false, true, true);
        this.title = title;
        this.titleColor = titleColor;
        this.titleBarColor = titleBarColor;
        //getContentPane().add(content, BorderLayout.CENTER);
        //setContentPane(content);
        //LineBorder line = new LineBorder(titleBarColor, 2);
        //setBorder(line);
        setBorder(BorderFactory.createRaisedBevelBorder());
        this.getDesktopIcon().setUI(new KDesktopIconUI(title, titleBarColor, titleColor));
        setUI(new KInternalFrameUI(this));
    package KComponent;
    import javax.swing.plaf.basic.*;
    import javax.swing.*;
    import java.awt.*;
    import Theme.*;
    public class KInternalFrameUI extends BasicInternalFrameUI {
      public KInternalFrameUI(JInternalFrame frame) {
        super(frame);
      protected void installDefaults(){
          Icon frameIcon = frame.getFrameIcon();
          frame.setFrameIcon(null);
          /* enable the content pane to inherit background color from its
             parent by setting its background color to null. Fixes bug#
             4268949. */
          JComponent contentPane = (JComponent) frame.getContentPane();
          if (contentPane != null) {
            Color bg = contentPane.getBackground();
          else {
            Color bg = null;
          //LookAndFeel.installBorder(frame, "InternalFrame.border");
      protected JComponent createNorthPane(JInternalFrame w) {
        titlePane = new KInternalFrameTitlePane(w, w.getTitle(), Theme.DARK, Color.white);
        return titlePane;
    package KComponent;
    import javax.swing.plaf.basic.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.File;
    import Theme.*;
    public class KInternalFrameTitlePane extends BasicInternalFrameTitlePane implements ActionListener {
      private JInternalFrame frame;
      private final String PATH = "pics" + File.separator;
      private KButton maxButton;
      private KButton minButton;
      private KButton normButton;
      private JLabel titleLabel;
      private File maxIcon = new File(PATH, "maximize.gif");
      private File maxOver = new File(PATH, "maximize_rollover.gif");
      private File minIcon = new File(PATH, "minimize.gif");
      private File minOver = new File(PATH, "minimize_rollover.gif");
      private File norIcon = new File(PATH, "normal.gif");
      private File norOver = new File(PATH, "normal_rollover.gif");
      String title;
      Color activeTitle;
      Color activeTitleText;
      Color inactiveTitle;
      Color inactiveTitleText;
      public KInternalFrameTitlePane(JInternalFrame frame, String title, Color activeTitle, Color activeTitleText) {
        super(frame);
        this.frame = frame;
        this.title = title;
        this.activeTitle = activeTitle;
        this.activeTitleText = activeTitleText;
        //this.inactiveTitle = inactiveTitle;
        //this.inactiveTitleText = inactiveTitleText;
        installTitlePane();
      public void installTitlePane() {
        titleLabel = new JLabel(" " + title + " ");
        titleLabel.setFont(new Font("verdana", Font.PLAIN, 11));
        titleLabel.setForeground(activeTitleText);
        titleLabel.setBorder(null);
        titleLabel.setOpaque(false);
        File icon = new File(PATH, "maximize.gif");
        File rollover = new File(PATH, "maximize_rollover.gif");
        maxButton = new KButton(icon, rollover, rollover, false);
        maxButton.setOpaque(false);
        maxButton.setToolTipText("Maximize window");
        maxButton.setActionCommand("maximize");
        //maxButton.addActionListener(this);
        icon = new File(PATH, "minimize.gif");
        rollover = new File(PATH, "minimize_rollover.gif");
        minButton = new KButton(icon, rollover, rollover, false);
        minButton.setOpaque(false);
        minButton.setToolTipText("Minimize window");
        minButton.setActionCommand("minimize");
        //minButton.addActionListener(this);
        icon = new File(PATH, "normal.gif");
        rollover = new File(PATH, "normal_rollover.gif");
        normButton = new KButton(icon, rollover, rollover, false);
        normButton.setOpaque(false);
        normButton.setToolTipText("Normalize window");
        normButton.setActionCommand("normal");
        //normButton.addActionListener(this);
        JPanel buttonHeader = new JPanel(new GridLayout(1, 3, 0, 0));
        buttonHeader.setOpaque(false);
        buttonHeader.add(minButton);
        buttonHeader.add(normButton);
        buttonHeader.add(maxButton);
        JPanel titlePane = new JPanel(new BorderLayout());
        titlePane.setBackground(activeTitle);
        titlePane.add(titleLabel, BorderLayout.WEST);
        titlePane.add(buttonHeader, BorderLayout.EAST);
        setBackground(activeTitle);
        setLayout(new BorderLayout());
        //add(titleLabel, BorderLayout.WEST);
        //add(buttonHeader, BorderLayout.EAST);
        add(titlePane, BorderLayout.CENTER);
        //installDefaults();
        createActions();
        enableActions();
        //createActionMap();
        assembleSystemMenu();
        createButtons();
      protected void createButtons() {
          minButton.addActionListener(iconifyAction);
          minButton.setActionCommand("minimize");
          minButton.addActionListener(this);
          maxButton.addActionListener(maximizeAction);
          maxButton.setActionCommand("maximize");
          maxButton.addActionListener(this);
          normButton.addActionListener(restoreAction);
          normButton.setActionCommand("normal");
          normButton.addActionListener(this);
          //setButtonIcons();
      public void setButtonIcons() {}
      public void actionPerformed(ActionEvent e) {
        String command = e.getActionCommand();
        if (command.equals("maximize")) {
          maxButton.setEnabled(false);
          minButton.setEnabled(true);
        else if (command.equals("minimize")) {
          //maxButton.setEnabled(true);
          //minButton.setEnabled(false);
        else if (command.equals("normal")) {
          maxButton.setEnabled(true);
          minButton.setEnabled(true);
    package KComponent;
    import javax.swing.plaf.basic.BasicDesktopIconUI;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.File;
    import javax.swing.border.*;
    public class KDesktopIconUI extends BasicDesktopIconUI {
      private final String PATH = "pics" + File.separator;
      private File norIcon = new File(PATH, "normal.gif");
      private File norOver = new File(PATH, "normal_rollover.gif");
      JComponent iconPane;
      String title;
      Color activeTitle;
      Color activeTitleText;
      KButton norButton;
      MouseInputListener mouseInputListener;
      public KDesktopIconUI(String title, Color activeTitle, Color activeTitleText) {
        this.title = title;
        this.activeTitle = activeTitle;
        this.activeTitleText = activeTitleText;
      protected void installComponents() {
          frame = desktopIcon.getInternalFrame();
          norButton = new KButton(norIcon, norOver, norOver, false);
          norButton.setOpaque(true);
          norButton.setBackground(activeTitle);
          iconPane = new JPanel(new BorderLayout());
          JLabel jlTitle = new JLabel(" " + title + " ");
          jlTitle.setFont(new Font("verdana", Font.PLAIN, 11));
          jlTitle.setForeground(activeTitleText);
          jlTitle.setBackground(activeTitle);
          jlTitle.setOpaque(true);
          iconPane.add(jlTitle, BorderLayout.CENTER);
          iconPane.add(norButton, BorderLayout.EAST);
          desktopIcon.setLayout(new BorderLayout());
          desktopIcon.add(iconPane, BorderLayout.CENTER);
          desktopIcon.setBackground(activeTitle);
          desktopIcon.setForeground(activeTitleText);
          iconPane.setBorder(BorderFactory.createRaisedBevelBorder());
          desktopIcon.setBorder(null);
      protected void installListeners() {
          mouseInputListener = createMouseInputListener();
          desktopIcon.addMouseMotionListener(mouseInputListener);
          desktopIcon.addMouseListener(mouseInputListener);
          norButton.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
              deiconize();
      public Dimension getMinimumSize(JComponent c) {
          return iconPane.getMinimumSize();
      public Dimension getMaximumSize(JComponent c){
          return iconPane.getMaximumSize();
      public Dimension getPreferredSize(JComponent c) {
          JInternalFrame iframe = desktopIcon.getInternalFrame();
          Border border = iframe.getBorder();
          int w2 = 157;
          int h2 = 18;
          //if(border != null)
              //h2 += border.getBorderInsets(iframe).bottom +
                //    border.getBorderInsets(iframe).top;
          return new Dimension(w2, h2);
      protected void uninstallComponents() {
          desktopIcon.setLayout(null);
          desktopIcon.remove(iconPane);
    package KComponent;
    import javax.swing.*;
    import java.awt.*;
    import Theme.*;
    import javax.swing.plaf.metal.*;
    public class KDesktop extends JDesktopPane {
      ImageIcon icon;
      boolean isWatermark;
      JInternalFrame gb, proj, stat, cal;
      boolean gbOpen, projOpen, statOpen, calOpen;
      public KDesktop(boolean isWatermark) {
        this.isWatermark = isWatermark;
        icon = Theme.getBackground();
        setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
      public void setBackgroundImage(ImageIcon i) {
        icon = i;
      public ImageIcon getBackgroundImage() {
        return icon;
      public void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (!isWatermark) {
          if (getWidth() > icon.getIconWidth() || getHeight() > icon.getIconHeight()){
            g.drawImage(icon.getImage(), 0,0, getWidth(), getHeight(), null);
          else {
            if (getProportionalHeight(getWidth()) < getHeight()) {
              g.drawImage(icon.getImage(), 0, 0,
                          getProportionalWidth(getHeight()), getHeight(), null);
            else
              g.drawImage(icon.getImage(), 0,0,
                          getWidth(), getProportionalHeight(getWidth()), null);
        else {
          int w = icon.getIconWidth();
          int h = icon.getIconHeight();
          if (w == '\u0000' || h == '\u0000') {
            super.paint(g);
          else {
            int currX = 0;
            int currY = 0;
            boolean keepPainting = true;
            while (keepPainting) {
              if (currX < (getWidth()+w/2)) {
                g.drawImage(icon.getImage(), currX, currY, null);
                currX += w;
              else if (currY < (getHeight()+h/2)) {
                currX = 0;
                currY += h;
                g.drawImage(icon.getImage(), currX, currY, null);
              else keepPainting = false;
      public int getProportionalHeight(int width) {
        double percentage = (double)width/icon.getIconWidth();
        return (int)(percentage*icon.getIconHeight());
      public int getProportionalWidth(int height) {
        double percentage = (double)height/icon.getIconHeight();
        return (int)(percentage*icon.getIconWidth());
    }Any ideas? I don't see how everything could work fine within the JBuilder environment and then screw up when I compile the code.
    Thanks for any help.

    And this is how I call up the UI from my main function:
    displayFrame.setUI(new MyInternalFrameUI(intFrame));Thanks!

  • A Internal frame problem: Please help me

    How can you add a panel to internal frame and show it. I add a image buffer to a panel and then I want to add that panel to internal frame which exists in a main frame. Please help me with code snippet as I am unable to it since morning and struck with my progress in my work. I will be thanki ful/
    regards,
    Ravi.

    Have a look at the code I took from the excellent FREE java swing book you can get here http://www.manning.com/sbe/
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    public class CommonLayouts extends JFrame {
    public Integer LAYOUT_FRAME_LAYER = new Integer(1);
    public CommonLayouts() {
    super("Common Layout Managers");
    setSize(500, 460);
    JDesktopPane desktop = new JDesktopPane();
    getContentPane().add(desktop);
    JInternalFrame fr1 =
    new JInternalFrame("FlowLayout", true, true);
    fr1.setBounds(10, 10, 150, 150);
    Container c = fr1.getContentPane();
    c.setLayout(new FlowLayout());
    c.add(new JButton("1"));
    c.add(new JButton("2"));
    c.add(new JButton("3"));
    c.add(new JButton("4"));
    desktop.add(fr1, 0);
    fr1.show();
    JInternalFrame fr2 =
    new JInternalFrame("GridLayout", true, true);
    fr2.setBounds(170, 10, 150, 150);
    c = fr2.getContentPane();
    c.setLayout(new GridLayout(2, 2));
    c.add(new JButton("1"));
    c.add(new JButton("2"));
    c.add(new JButton("3"));
    c.add(new JButton("4"));
    desktop.add(fr2, 0);
    fr2.show();
    JInternalFrame fr3 =
    new JInternalFrame("BorderLayout", true, true);
    fr3.setBounds(330, 10, 150, 150);
    c = fr3.getContentPane();
    c.add(new JButton("1"), BorderLayout.NORTH);
    c.add(new JButton("2"), BorderLayout.EAST);
    c.add(new JButton("3"), BorderLayout.SOUTH);
    c.add(new JButton("4"), BorderLayout.WEST);
    desktop.add(fr3, 0);
    fr3.show();
    JInternalFrame fr4 = new JInternalFrame("BoxLayout - X",
    true, true);
    fr4.setBounds(10, 170, 250, 80);
    c = fr4.getContentPane();
    c.setLayout(new BoxLayout(c, BoxLayout.X_AXIS));
    c.add(new JButton("1"));
    c.add(Box.createHorizontalStrut(12));
    c.add(new JButton("2"));
    c.add(Box.createGlue());
    c.add(new JButton("3"));
    c.add(Box.createHorizontalGlue());
    c.add(new JButton("4"));
    desktop.add(fr4, 0);
    fr4.show();
    JInternalFrame fr5 = new JInternalFrame("BoxLayout - Y",
    true, true);
    fr5.setBounds(330, 170, 150, 200);
    c = fr5.getContentPane();
    c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS));
    c.add(new JButton("1"));
    c.add(Box.createVerticalStrut(10));
    c.add(new JButton("2"));
    c.add(Box.createGlue());
    c.add(new JButton("3"));
    c.add(Box.createVerticalGlue());
    c.add(new JButton("4"));
    desktop.add(fr5, 0);
    fr5.show();
    JInternalFrame fr6 =
    new JInternalFrame("SpringLayout", true, true);
    fr6.setBounds(10, 260, 250, 170);
    c = fr6.getContentPane();
    c.setLayout(new SpringLayout());
    c.add(new JButton("1"), new SpringLayout.Constraints(
    Spring.constant(10),
    Spring.constant(10),
    Spring.constant(120),
    Spring.constant(70)));
    c.add(new JButton("2"), new SpringLayout.Constraints(
    Spring.constant(160),
    Spring.constant(10),
    Spring.constant(70),
    Spring.constant(30)));
    c.add(new JButton("3"), new SpringLayout.Constraints(
    Spring.constant(160),
    Spring.constant(50),
    Spring.constant(70),
    Spring.constant(30)));
    c.add(new JButton("4"), new SpringLayout.Constraints(
    Spring.constant(10),
    Spring.constant(90),
    Spring.constant(50),
    Spring.constant(40)));
    c.add(new JButton("5"), new SpringLayout.Constraints(
    Spring.constant(120),
    Spring.constant(90),
    Spring.constant(50),
    Spring.constant(40)));
    desktop.add(fr6, 0);
    fr6.show();
    desktop.setSelectedFrame(fr6);
    public static void main(String argv[]) {
    CommonLayouts frame = new CommonLayouts();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

  • How to make Internal Frame on Focus

    Hi All,
    i have an application where in i have a JInternalFrame within in A JFrame.
    Queries:
    1.I want to make JInternalFrame focused,(without clicking on any portoion of Internal Frame) once i run the apllication(java Demo)
    2.i want to fix the JInternal Frame.(Non movable)
    //Demo.java
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;     
    import javax.swing.event.*;     
    import javax.swing.border.*;          
    public class Demo extends JFrame implements ActionListener {
    static JDesktopPane desk;
    String labelstr="Test ";
    JPanel contentpane;
    JLabel titlelabel;
    public Demo() {
              setTitle("Swing Test");
                    contentpane=(JPanel)getContentPane();
                    contentpane.setLayout(new BorderLayout());
                    desk=new JDesktopPane();     
                    desk.setBackground(Color.gray);
                    contentpane.add("Center",desk);
                    titlelabel=new JLabel(labelstr);
                    titlelabel.setForeground(Color.black);
                    titlelabel.setBorder(new BevelBorder(BevelBorder.LOWERED));
                    getContentPane().add(titlelabel,BorderLayout.SOUTH);            
              public void actionPerformed(ActionEvent e) {
                 public static void main(String args[]) {     
                    try  {
                      UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
                      //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                     }catch(Exception e) {
                                               System.out.println("Error loading L&F:"+e);     
                                               JOptionPane.showMessageDialog(null,e);
                    JFrame frame=new Demo();
                    frame.setSize(800,600);
                    frame.setVisible(true);
                      InternalFr jif=new InternalFr();
                      jif.start();
                    frame.addWindowListener(new CloseWindow());
           class CloseWindow extends WindowAdapter {
             public void windowClosing(WindowEvent we) {
                 Window w=we.getWindow();
                 w.dispose();
                 System.exit(0);
          }//InternalFr.java
    import java.io.*;
         import java.net.*;
         import java.lang.*;
         import java.awt.*;
         import java.awt.event.*;
         import javax.swing.*;
         import javax.swing.border.*;
         import javax.swing.text.*;
         public class InternalFr extends JInternalFrame {
             JLabel jlName, jlPass;
             static JTextField jtName,jtPass;
                 JButton submit,cancel;
            public InternalFr() {  
              super( "InternalFr");
              Icon img=new ImageIcon("Neticon.gif");
              setFrameIcon(img);
              JPanel contentpane=(JPanel)getContentPane();
               contentpane.setLayout(null);
              JPanel mainpanel=new JPanel();
              mainpanel.setLayout(null);
              mainpanel.setBounds(0,0,290,180);
              jlName=new JLabel("Username   :");
              jlName.setBounds(20,20,180,20);
              jlName.setForeground(Color.black);
              jtName=new JTextField();
              jtName.setBounds(150,20,100,20);
              mainpanel.add(jtName);
              mainpanel.add(jlName);
              jlPass=new JLabel("Password   :");
              jlPass.setBounds(20,50,180,20);
              jlPass.setForeground(Color.black);
              jtPass=new JTextField();
              jtPass.setBounds(150,50,100,20);
              mainpanel.add(jlPass);
              mainpanel.add(jtPass);
              JPanel buttonpanel=new JPanel();
              buttonpanel.setLayout(null);
              buttonpanel.setBounds(30,90,215,30);
              buttonpanel.setBorder(new EtchedBorder(EtchedBorder.RAISED));
              submit=new JButton("Submit");
              submit.setMnemonic('O');
              submit.setBounds(5,5,100,20);
              buttonpanel.add(submit);
              submit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                 if(ae.getSource()==submit)  {
            cancel=new JButton("Cancel");
              cancel.setMnemonic('C');
              cancel.setBounds(110,5,100,20);
              buttonpanel.add(cancel);
              cancel.addActionListener(new ActionListener() {
                 public void actionPerformed(ActionEvent ae) {
                      Object obj=ae.getSource();
                     if(obj==cancel){
                          System.exit(0);
           contentpane.add(buttonpanel);
           contentpane.add(mainpanel);
        public void start()  {
             InternalFr at=new InternalFr();
             at.setSize(290,180);
            at.setLocation(220,150);
            at.setVisible(true);
            Demo.desk.add(at);
      }Thanks
    Mohan

    To give focus to an internal frame, do the following (where iFrame is your internal frame):try {
        iFrame.setIcon( false );  // In case it is minimized
        iFrame.moveToFront();     // Make sure it is in front
        iFrame.requestFocus();    // Ask for focus
        iFrame.setSelected( true );  // Select it
    } catch( java.beans.PropertyVetoException pve ) {
    }

  • Internal Frames problem

    Hi,
    I am writing a piece of code where I want to able to choose from a menu a screen that displays multiple graphs (using Internal frames.) I am using cardlayout to bring up the various options I choose from the menu. I have simplified my program as much as possible but I still seem to be getting the same error
    Exception in thread "main" java.lang.IllegalArgumentException: adding a window to a container .......
    I know I shouldn't be adding a window to a container but I can't see how I can change my code so it has the functionality I desire.
    Here is the code I am using
    import java.awt.*;
    import javax.swing.*;
    public class Test extends JFrame
         public Test()
             JPanel card1 = new JPanel();
             card1.add(new InternalFrameDemo());
              getContentPane().add(card1);
        public static void main(String[] args)
              Test frame = new Test();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.setSize(200, 200);
              frame.setLocationRelativeTo( null );
              frame.setVisible(true);
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class InternalFrameDemo extends JFrame
        JDesktopPane desktop;
        static final int xOffset = 30, yOffset = 30;
        private JLabel graph1;
        private String Graph1;
        public InternalFrameDemo() {
            super("InternalFrameDemo");
            //Make the big window be indented 50 pixels from each edge
            //of the screen.
            int inset = 50;
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setBounds(inset, inset,
                      screenSize.width  - inset*2,
                      screenSize.height - inset*2);
            //Set up the GUI.
            desktop = new JDesktopPane(); //a specialized layered pane
            createFrame(); //create first "window"
            setContentPane(desktop);
            //Make dragging a little faster but perhaps uglier.
            desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
        //Create a new internal frame.
        protected void createFrame() {
            MyInternalFrame frame = new MyInternalFrame();
            frame.setVisible(true);
            desktop.add(frame);
            try {
                frame.setSelected(true);
            } catch (java.beans.PropertyVetoException e) {}
        //Quit the application.
        protected void quit() {
            System.exit(0);
       public void MyInternalFrame() {
         System.out.println("graph1");
         graph1 = new JLabel("", 
                       new ImageIcon("../images/Graph1.jpg"),
                       JLabel.CENTER);
         getContentPane().add(graph1);
         //...Then set the window size or call pack...
         setSize(500,550);
    }If anyone could point me in the right direction it would be great. Thanks in advance!

    But I actually do not understand what that card layout thing is all about. If you want to hide/show internal frames you can simply use setVisible() and setSelected() like examplified below (I did put all code in the same file for my convenince). I have put a text in the label so that you can see that it is replaced. Using aJLabel to show an image is however a little bit weird.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    class MyInternalFrame extends JInternalFrame
      private JLabel graph1;
      public MyInternalFrame(String text)
        graph1 = new JLabel(text, 
                            new ImageIcon("../images/Graph1.jpg"),
                            JLabel.CENTER);
        getContentPane().add(graph1);
        setSize(500,550);
    public class InternalFrameDemo extends JFrame
      private JDesktopPane desktop;
      private final MyInternalFrame[] frames;
      public InternalFrameDemo()
        super("InternalFrameDemo");
        frames = new MyInternalFrame[3];
        //Make the big window be indented 50 pixels from each edge of the screen.
        int inset = 50;
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(inset, inset,
                  screenSize.width  - inset*2,
                  screenSize.height - inset*2);
        //Set up the GUI.
        desktop = new JDesktopPane(); //a specialized layered pane
        setContentPane(desktop);
        frames[0] = createFrame("Hello world!");
        frames[1] = createFrame("Hello again, world!");
        frames[2] = createFrame("Goodbye cruel world!");
        desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
        setSize(500, 500);
        Thread animThread = new Thread()
            public void run()
              for (int i = 0; i < frames.length; ++i)
                final int frameId = i;
                SwingUtilities.invokeLater(new Runnable()
                    public void run()
                      // Hide frame that is showing.
                      if (frameId != 0)
                        frames[frameId - 1].setVisible(false);
                      System.out.println("Replacing image: " + frameId);
                      frames[frameId].setVisible(true);
                      try
                        frames[frameId].setSelected(true);
                      catch (java.beans.PropertyVetoException exc)
                        exc.printStackTrace();
                try
                  Thread.sleep(3000);
                catch (InterruptedException exc)
                  exc.printStackTrace();
        animThread.start();
      //Create a new internal frame.
      protected MyInternalFrame createFrame(String text)
        MyInternalFrame frame = new MyInternalFrame(text);
        desktop.add(frame);
        return frame;
      public static void main(String[] args)
        JFrame frame = new InternalFrameDemo();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }Using lazy initialization where you postpone the creation of an internal frame until it is actually shown would be an improvement.
    The setVisible/Selected() call can of course be triggered by something else in your application.
    Note that changes of swing components shall be made in the EDT.

  • Openinig internal frames by clicking menuitems

    Hi,
    I have been trying to open internal frames by clicking menu items but
    have not been able to do so because menuitems support only action listeners and not all mouse event listeners.
    Actually I wanted the event to return the frame n which the event has occured
    e.g., event,getframe(), so that I could create an internal frame in the same frame.
    But such kind of function is unavailable.
    Kindly suggest something...the code is given below (it works perfectly)..it need a text file from which the menuitems are read. This is also given below:
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.lang.*;
    import java.io.*;
    import javax.swing.plaf.metal.*;
    import javax.swing.*;
    import javax.swing.undo.*;
    class Action extends JFrame
         ActionListener FListener = new ActionListener()
               public void actionPerformed(ActionEvent event)
                  {System.out.println("Menu item " + event.getActionCommand(  ) +"  of File Menu was pressed.");}
        ActionListener EListener = new ActionListener()
               public void actionPerformed(ActionEvent event)
                  {System.out.println("Menu item " + event.getActionCommand(  ) +"  of Edit Menu was pressed.");}
        ActionListener VListener = new ActionListener()
               public void actionPerformed(ActionEvent event)
                  {System.out.println("Menu item " + event.getActionCommand(  ) +"  of View Menu was pressed.");}
        ActionListener TListener = new ActionListener()
               public void actionPerformed(ActionEvent event)
                  {System.out.println("Menu item " + event.getActionCommand(  ) +"  of Tools Menu was pressed.");}
        ActionListener HListener = new ActionListener()
               public void actionPerformed(ActionEvent event)
                  {System.out.println("Menu item " + event.getActionCommand(  ) +"  of Help Menu was pressed.");}
         /*     protected class MyUndoableEditListener  implements UndoableEditListener
                  protected UndoManager undo = new UndoManager();
                  public void undoableEditHappened(UndoableEditEvent e)
                 //Remember the edit and update the menus
                 undo.addEdit(e.getEdit());
                 undoAction.updateUndoState();
                 redoAction.updateRedoState();
          class framecreator extends JFrame
               public JFrame CreateFrame(JMenuBar m)
             JDesktopPane jdp= new JDesktopPane();
              JFrame.setDefaultLookAndFeelDecorated(true);       
            JFrame frame = new JFrame("PEA");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         
            frame.setContentPane(jdp);
            jdp.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);          
            frame.setJMenuBar(m);       
            frame.pack();
            frame.setVisible(true);
            frame.setSize(600,600);
            frame.setLocation(100,100);
            return frame;
          class internalframecreator extends JFrame
             public JInternalFrame CreateInternalFrame(JFrame f)
              Container cp= f.getContentPane();
              JInternalFrame jif = new JInternalFrame("internal frame",true,true,true,true);
             cp.add(jif);
             jif.pack();
             jif.setVisible(true);
             jif.setSize(300,300);
             jif.setLocation(80,80);
             return jif;    
      class menucreator
         public String[] filereader()
              String[] menuitems=new String[21];
              int i=0,j=0;
              String record = null;            
                   for(int h=0;h<21;h++){ menuitems[h]=null;}
               try { 
                    FileReader fr = new FileReader("projectconfig2.txt");  
                     BufferedReader br = new BufferedReader(fr);
                         while ( (record=br.readLine()) != null )
                           StringTokenizer st = new StringTokenizer(record,"\n");
                             while (st.hasMoreTokens())
                          menuitems= st.nextToken();
         System.out.println(menuitems[i]);
    i++;
                   /* StringTokenizer st1 = new StringTokenizer(record,"\n");
         while (st1.hasMoreTokens())
         while ( (record=br.readLine()) != null )
         StringTokenizer st2 = new StringTokenizer(record,":");
         while (st2.hasMoreTokens())
         menuitems[i][j]= st2.nextToken();
         System.out.println(menuitems[i][j]);
              j++;      
         i++;
              } catch(IOException e)
         System.out.println("Error reading file");
         return (menuitems);
         public JMenuBar CreateMenu(Action a, String menuitems[])
    JMenuBar mb = new JMenuBar();
    JMenu fileB = new JMenu(menuitems[0]);
    JMenu editB = new JMenu(menuitems[8]);
    JMenu viewB = new JMenu(menuitems[11]);
    JMenu toolsB = new JMenu(menuitems[14]);
    JMenu helpB = new JMenu(menuitems[18]);
    mb.add(fileB);
    mb.add(editB);
    mb.add(viewB);
    mb.add(toolsB);
    mb.add(helpB);
    JMenuItem newpolicyB = new JMenuItem(menuitems[1]);
    newpolicyB.addActionListener(a.FListener);
    //newpolicyB.addUndoableEditListener(new MyUndoableEditListener());
    JMenuItem openB = new JMenuItem(menuitems[2]);
    openB.addActionListener(a.FListener);
    JMenuItem saveB = new JMenuItem(menuitems[3]);
    saveB.addActionListener(a.FListener);
    JMenuItem saveasB = new JMenuItem(menuitems[4]);
    saveasB.addActionListener(a.FListener);
    JMenuItem printxmlB = new JMenuItem(menuitems[5]);
    printxmlB.addActionListener(a.FListener);
    JMenuItem printreadablepolicyB = new JMenuItem(menuitems[6]);
    printreadablepolicyB.addActionListener(a.FListener);
    JMenuItem exitB = new JMenuItem(menuitems[7]);
    exitB.addActionListener(a.FListener);
    JMenuItem undoB = new JMenuItem(menuitems[9]);
    undoB.addActionListener(a.EListener);
    JMenuItem redoB = new JMenuItem(menuitems[10]);
    redoB.addActionListener(a.EListener);
    JMenuItem xmlB = new JMenuItem(menuitems[12]);
    xmlB.addActionListener(a.VListener);
    JMenuItem readablepolicyB = new JMenuItem(menuitems[13]);
    readablepolicyB.addActionListener(a.VListener);
    JMenuItem validateB = new JMenuItem(menuitems[15]);
    validateB.addActionListener(a.TListener);
    JMenuItem signandpublishB = new JMenuItem(menuitems[16]);
    signandpublishB.addActionListener(a.TListener);
    JMenuItem optionsB = new JMenuItem(menuitems[17]);
    optionsB.addActionListener(a.TListener);
    JMenuItem pemanualB = new JMenuItem(menuitems[19]);
    pemanualB.addActionListener(a.HListener);
    JMenuItem aboutB = new JMenuItem(menuitems[20]);
    aboutB.addActionListener(a.HListener);
    fileB.add(newpolicyB);
    fileB.add(openB);
    fileB.add(saveB);
    fileB.add(saveasB);
    fileB.add(printxmlB);
    fileB.add(printreadablepolicyB);
    fileB.add(exitB);
    editB.add(undoB);
    editB.add(redoB);
    viewB.add(xmlB);
    viewB.add(readablepolicyB);
    toolsB.add(validateB);
    toolsB.add(signandpublishB);
    toolsB.add(optionsB);
    helpB.add(pemanualB);
    helpB.add(aboutB);
    mb.setSize(300,200);
    mb.setVisible(true);
    return mb;
    public class project
    public static void main(String args[])
              Action a =new Action();           
              framecreator fc=new framecreator();           
         menucreator mc=new menucreator();     
         internalframecreator ifc= new internalframecreator();          
         ifc.CreateInternalFrame(fc.CreateFrame(mc.CreateMenu(a,mc.filereader())));
    The text file called projectconfig2.txt
    File
    New Policy
    Open...
    Save
    Save As...
    Print XML
    Print Readable Policy
    Exit
    Edit
    Undo
    Redo
    View
    XML
    Readable Policy
    Tools
    Validate
    Sign & Publish
    Options
    Help
    PE Manual
    About

    The problem is that you are adding the JInternalFrame to the JFrame's contentPane when it should be added to the JDesktopPane. See your code ...
    public JInternalFrame CreateInternalFrame( JFrame  f )
         Container  cp = f.getContentPane();
         JInternalFrame jif = new JInternalFrame("internal frame",true,true,true,true);
         cp.add( jif );

  • How do I only allow 1 internal frame to be added?

    Could you pls show me how can I do this, I need some code to learn how this code work.
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class Test1a extends JFrame
         private JLabel label1;
    //     private JLabel label2;
         private JLabel label3;
         private JLabel label4;
         private JLabel label5;
         private JDesktopPane theDesktop;
         public Test1a()
              super("TESTING JLABEL");
              setLayout(new BorderLayout(5, 5));
            JMenuBar bar = new JMenuBar();
          JMenu addMenu = new JMenu( "Add" );
          JMenuItem newFrame = new JMenuItem( "Internal Frame" );
          addMenu.add( newFrame );
          bar.add( addMenu );
          setJMenuBar( bar );
           theDesktop = new JDesktopPane();
          add( theDesktop, BorderLayout.CENTER );
          newFrame.addActionListener(
             new ActionListener()
                // display new internal window
                public void actionPerformed( ActionEvent event )
                   // create internal frame
                   JInternalFrame frame = new JInternalFrame("Internal Frame", true, true, true, true);
                   MyJPanel panel = new MyJPanel();
                   frame.add( panel, BorderLayout.CENTER );
                   frame.pack(); // set internal frame to size of contents
                   theDesktop.add( frame );
                   frame.setVisible( true );
              label1= new JLabel ();
              label1.setText("Label 1");
              add(label1, BorderLayout.WEST);
         //     label2= new JLabel ("Label 2", SwingConstants.CENTER);
         //   add(label2, BorderLayout.CENTER);
              label3= new JLabel ();
              label3.setText("Label 3");
              add(label3, BorderLayout.EAST);
              label4= new JLabel ("Label 4", SwingConstants.CENTER);
              add(label4, BorderLayout.NORTH);
              label5= new JLabel ("Label 5", SwingConstants.CENTER);
              add(label5, BorderLayout.SOUTH);
    =============================================
    import java.awt.*;
    import javax.swing.*;
    // class to display an ImageIcon on a panel
    class MyJPanel extends JPanel
       private ImageIcon imageIcon;
       // load image
       public MyJPanel()
          imageIcon = new ImageIcon("yellowflowers.png");
       // display imageIcon on panel
       public void paintComponent( Graphics g )
          super.paintComponent( g );
          imageIcon.paintIcon( this, g, 0, 0 );
       public Dimension getPreferredSize()
          return new Dimension( imageIcon.getIconWidth(), imageIcon.getIconHeight() ); 
    ========================================
    import javax.swing.*;
    public class Test1b
         public static void main (String args[])
              Test1a test1a = new Test1a();
              test1a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              test1a.setSize(800, 600);
              test1a.setVisible(true);
    }

    You where given an answer in your original posting:
    http://forum.java.sun.com/thread.jspa?threadID=5146301

Maybe you are looking for

  • Remote for iPhone - Choosing speakers

    Ever since they brought out an update for Remote for the iPhone I have been unable to change the speaker selection. Where has the option gone? It used to be under settings but I cannot find it. Am I being really dense?

  • Error writing data in a flat file using UTL_FILE feature

    Hi All, I have written a package which fetches data from four different cursors and inserts into a temporary table. Now this temporary table is used to write data in a file using the UTL_FILE feature. fhandler := UTL_FILE.fopen (l_path,'Demand_Transa

  • Layout in reports

    In some report there is a field given as Layout, for example MR11. When I did F4, the system message was no layout found. Where we define layout in spro? how I can make the layout in selection drop down  when I do F4? What is the purpose of the layou

  • Here Drive not working in Nigeria

    here drive on my Lumia isn't working in Nigeria either. The key reason I got a Nokia. Moderator's notes: The post was edited. A more appropriate subject is provided. Solved! Go to Solution.

  • Fix for Blasting Fans with 10.4.4 yet??

    Hello everybody, It's been a while since I've checked back at these forums, but I couldn't find a solution going over some posts today. My fans have been CRAZY since 10.4.3, and 10.4.4 didn't help one bit. They're fine when in Reduced settings, which