Modal JInternal Frames?

Is there a possibility to create REAL custom modal JInternalFrames? I mean without using JOptionPane.showInternal.. since these cannot be customized in size, and dont return a reference.
felix

i believe what they were referring to is that you should not use a JDialog AS an internal frame and that you should use the JOptionPane and JInternalFrame classes.
in your case, it is still perfectly fine to pop up a modal JDialog to ask for user input...
and i'm pretty sure you were referring to the argument between myself and James. and you are perfectly fine as your question is general enough to not need code. :)

Similar Messages

  • Saving contents of jinternal frame

    Hi, I seem to have a problem saving files from jinternal frames. I created two files, the main GUI which holds the jdesktop pane and the other file (Documento) extends jinternalframe. I want to be able to save the current (active) jinternal frame but I have no idea how to do it. can anyone help me?
    import javax.swing.JInternalFrame;
    import javax.swing.JDesktopPane;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.JMenuBar;
    import javax.swing.JFrame;
    import javax.swing.KeyStroke;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.Graphics.*;
    import javax.swing.JOptionPane;
    import java.io.*;
    import java.util.*;
    *This is the main GUI of the program.
    public class mainGUI extends JFrame
                                   implements ActionListener,
                                    KeyListener{
        JDesktopPane desktop;
        Documento frame;
         private Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
         private JPanel toolbar, editarea, resultarea, blankPanel;
         private JMenu file, edit, project;
         private JMenuItem f_open, f_new, f_save, f_saveas, f_exit, e_select, e_copy, e_paste, p_compile;
         private JTextArea resultfield, editfield,editArea, tstr;
         private JButton bcompile;
         private JFileChooser fc = new JFileChooser();
         private String filepath;
         private ImageIcon bugicon;
         private static int docNum = 0;
         private boolean b_openfile;
         File filename;
        public mainGUI() {
            super("DGJ Program Scanner");
            setSize(800,600);
              setLocation((screen.width-800)/2, (screen.height-600)/2);
            /*Creates the workspace*/
            desktop = new JDesktopPane();
            setContentPane(desktop);
            setJMenuBar(createMenuBar());
            /*Make dragging a little faster*/
            desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
          *This function creates the menu bar
        protected JMenuBar createMenuBar() {
             /*Initializes/instantiates the menu bar and its items*/
              file = new JMenu("File");
              edit = new JMenu("Edit");
              project = new JMenu("Project");
              f_new = new JMenuItem("Create new file");
              f_open = new JMenuItem("Open file...");
              f_save = new JMenuItem("Save current file");
              f_saveas = new JMenuItem("Save As...");
              f_exit = new JMenuItem("Exit program");
              e_select = new JMenuItem("Select All");
              e_copy = new JMenuItem("Copy selected");
              e_paste = new JMenuItem("Paste selected");
              p_compile = new JMenuItem("Scan current file for errors");
              /*Adds listeners to the menu items*/
              f_open.setActionCommand("f_open");
              f_open.addActionListener(this);
              f_save.setActionCommand("f_save");
              f_save.addActionListener(this);
              f_saveas.addActionListener(this);
              f_saveas.setActionCommand("f_saveas");
              f_new.setActionCommand("f_new");
              f_new.addActionListener(this);
              f_exit.setActionCommand("f_exit");
              f_exit.addActionListener(this);
              e_select.setActionCommand("e_select");
              e_select.addActionListener(this);
              e_paste.setActionCommand("e_paste");
              e_paste.addActionListener(this);     
              e_copy.setActionCommand("e_copy");
              e_copy.addActionListener(this);               
              /*Creates the icon of the bug*/
              bugicon = new ImageIcon("images/ladybug.gif");
              /*Creates the menu bar*/
              JMenuBar menu = new JMenuBar();
              menu.add(file);
                   file.add(f_new);
                   file.add(f_open);
                   file.add(f_save);
                   file.add(f_saveas);
                   file.add(f_exit);
              menu.add(edit);
                   edit.add(e_select);
                   edit.add(e_copy);
                   edit.add(e_paste);
              menu.add(project);
                   project.add(p_compile);
              /*Disables the save current file menu...(when program starts, no file is open yet)*/
              f_save.setEnabled(false);
              f_saveas.setEnabled(false);
            return menu;
        //React to menu selections.
        public void actionPerformed(ActionEvent e) {
            if ("f_new".equals(e.getActionCommand()))
            { //new
                createFrame(null);
                f_saveas.setEnabled(true);
            else if("f_open".equals(e.getActionCommand()))
            {//open documento
                   fc.setFileFilter(new SpanFilter());
                  int retval = fc.showOpenDialog(mainGUI.this);
                   tstr = new JTextArea();
                   /*This checks if the user has chosen a file*/
                if (retval == JFileChooser.APPROVE_OPTION) {
                    filename = fc.getSelectedFile();
                        filepath = filename.getPath();            
                        openFile(filename, new Point(30,30));       
            else if("f_save".equals(e.getActionCommand()))
                 try {
                      BufferedWriter out = new BufferedWriter(new FileWriter(filepath));
                      String str;
                      str = editArea.getText();
                      editArea.setText("");  
                      int length = str.length();
                      out.write(str, 0, length);
                      out.close();
                       } catch (Exception ex) {}
                       JInternalFrame fr = new JInternalFrame();
                       fr = desktop.getSelectedFrame();
                       Point p = fr.getLocation();
                        fr.dispose();    
                       openFile(filename, p);
            else if("f_saveas".equals(e.getActionCommand()))
                 fc.setFileFilter(new SpanFilter());
                  int retval = fc.showSaveDialog(mainGUI.this);
                if (retval == JFileChooser.APPROVE_OPTION) {
                    filename = fc.getSelectedFile();
                        filepath = filename.getPath();
                        if(!(filepath.contains(".dgj")))
                             filepath+=".dgj";
                      try {
                           BufferedWriter out = new BufferedWriter(new FileWriter(filepath));
                                String str;
                           str = editArea.getText();
                           int length = str.length();
                           out.write(str, 0, length);
                           out.close();
                       } catch (Exception ex) {}
                       Point p = frame.getLocation();
                        frame.dispose();
                   //     editArea.setText("");     
                       openFile(filename, p);
            else if("e_select".equals(e.getActionCommand()))
                 editArea.selectAll();
            else if("e_copy".equals(e.getActionCommand()))
                   editArea.copy();
            else if("e_paste".equals(e.getActionCommand()))
                 editArea.paste();
            else if("f_exit".equals(e.getActionCommand()))
            { //quit
                quit();
        public void openFile(File filename, Point p)
                        /*Reads the file*/
                        try {
                           BufferedReader in = new BufferedReader(new FileReader(filepath));
                             String str;
                             /*empties the textarea*/
                             tstr.setText("");
                             str = in.readLine();
                             /*Copy each line of the file into the temporary textarea*/
                           do{  
                          tstr.append(str);
                          str = in.readLine();
                          /* the "\n" is for the line to appear in the next line in the textarea,
                           * the "\r" is for windows system, wherein "\r" is required for the text
                           * to appear in beginning of the first line*/
                          if(str!=null)
                               tstr.append("\r\n");
                           }while (str != null);
                             /*Opens the new frame*/
                           createFrame(filename, filename.getName(), tstr.getText(), p);
                           in.close();
                       } catch (Exception ex){}
                      b_openfile = true;
                      f_save.setEnabled(true); 
                      f_saveas.setEnabled(true);   
         *Create a new internal frame.
        protected void createFrame(File f) {
             frame = new Documento(f);
         /*     frame = new JInternalFrame("Document "+(++docNum),
                  true, //resizable
                  true, //closable
                  true, //maximizable
                  true);
            docNum++;
              frame.setSize(600,400);
              frame.setLocation(20*(docNum%10), 20*(docNum%10));       
             editArea = new JTextArea();
              JScrollPane scroll = new JScrollPane(editArea);     
              editArea.addKeyListener(this);
              editArea.append("");
              frame.add(scroll);
            frame.setVisible(true); //necessary as of 1.3
            desktop.add(frame);
            try {
                frame.setSelected(true);
            } catch (java.beans.PropertyVetoException e) {}
          *Overwrite an existing internal frame for an open file
        protected void createFrame(File f, String title, String text, Point P) {
             frame = new Documento(title, f, P);
              frame.setSize(600,400);
              frame.setLocation(P); 
             editArea = new JTextArea();
              JScrollPane scroll = new JScrollPane(editArea);     
              editArea.setText("");
              editArea.addKeyListener(this);
              editArea.append(text);
              frame.add(scroll);
            frame.setVisible(true); //necessary as of 1.3
            desktop.add(frame);
            try {
                frame.setSelected(true);
            } catch (java.beans.PropertyVetoException e) {}
        //Quit the application.
        protected void quit() {
            System.exit(0);
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
        private static void createAndShowGUI() {
            //Make sure we have nice window decorations.
            //JFrame.setDefaultLookAndFeelDecorated(true);
            //Create and set up the window.
            mainGUI frame = new mainGUI();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Display the window.
            frame.setVisible(true);
        public void keyTyped(KeyEvent k){}
        public void keyPressed(KeyEvent k)
             if(k.getKeyCode()==10)
                  editArea.append("\r");           
        public void keyReleased(KeyEvent k){}
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }here's the one that extends jinternalframe
    import javax.swing.JInternalFrame;
    import javax.swing.plaf.InternalFrameUI;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.io.*;
    import java.util.*;
    /* Used by mainGUI.java */
    public class Documento extends JInternalFrame {
        static final int xOffset = 30, yOffset = 30;
         static JTextArea editArea;
         static int docNum = 0;
         static File file;
          *The constructer for a new documento
        public Documento(File file) {
            super("Document "+(++docNum),
                  true, //resizable
                  true, //closable
                  true, //maximizable
                  true);//iconifiable
            docNum++;
              this.file = file;
              setSize(600,400);
              setLocation(xOffset*(docNum%10), yOffset*(docNum%10));
    //        setUI(new InternalFrameUI());
         *The constructor for an existing documento
        public Documento(String title, File file, Point p) {
            super(title,
                  true, //resizable
                  true, //closable
                  true, //maximizable
                  true);//iconifiable
              this.file = file;             
              setSize(600,400);          
              setLocation(p);
    //        setUI(new InternalFrameUI());
        public int getNum()
             return docNum;
        public File getPath()
             return file;
    }I know it's pretty lengthy...it's probably all messed up since I'm lost :p
    Thanks if you could help me!

    I would be glad to help, but first I need a clarification. If I understand properly, you have two Java classes that you have created: the "main GUI" (which is most likely a JFrame extension in which the constructor adds a JDesktopPane to the content pane) and "Documento" (which you say is a JInternalFrame extension).
    My question is this: what do you mean by "save the current JInternalFrame"? Do you want to record its position, location, and identity? Do you want to save its contents?
    Thanks. Good luck. ;)

  • Modal Internal Frames and JCombos

    Hi,
    I'm trying to create a modal internal frame as suggested in Sun's TechTip:
    http://developer.java.sun.com/developer/JDCTechTips/2001/tt1220.html
    All I need is to block the input for the rest of the GUI, I don't care about real modality (the setVisible() call returns immediately).
    I need to have a JComboBox in my internal frame. It turns out that under JDK1.4.0/1.4.1 the list for the combo is visible only with the Windows Look And Feel, while in every other JDK version it's not visible, except for the portion falling out of the internal frame.
    The code to verify this follows. Does anybody know how to fix this? I've opened a bug for it, but I was wondering if someone can help in the forum...
    Run the application passing "Windows" or "CDE/Motif", click on "open" and play with the combo to observe the result.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class Modal {
    static class ModalAdapter
    extends InternalFrameAdapter {
    Component glass;
    public ModalAdapter(Component glass) {
    this.glass = glass;
    // Associate dummy mouse listeners
    // Otherwise mouse events pass through
    MouseInputAdapter adapter =
    new MouseInputAdapter(){};
    glass.addMouseListener(adapter);
    glass.addMouseMotionListener(adapter);
    public void internalFrameClosed(
    InternalFrameEvent e) {
    glass.setVisible(false);
    public static void main(String args[]) {
    System.out.println("Installed lookAndFeels:");
    UIManager.LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels();
    for(int i=0; i<lafInfo.length; i++) {
    System.out.println(lafInfo.getName());
    String lookAndFeel = null;
    if (args.length>0)
    lookAndFeel = args[0];
    initLookAndFeel(lookAndFeel);
    final JFrame frame = new JFrame(
    "Modal Internal Frame");
    frame.setDefaultCloseOperation(
    JFrame.EXIT_ON_CLOSE);
    final JDesktopPane desktop = new JDesktopPane();
    ActionListener showModal =
    new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    // Manually construct a message frame popup
    JOptionPane optionPane = new JOptionPane();
    optionPane.setMessage("Hello, World");
    optionPane.setMessageType(
    JOptionPane.INFORMATION_MESSAGE);
    // JInternalFrame modal = optionPane.
    // createInternalFrame(desktop, "Modal");
                        JInternalFrame modal = new JInternalFrame("test", true, true, true);
    JPanel jp = (JPanel )modal.getContentPane();
              JComboBox jcb = new JComboBox(new String[]{"choice a", "choice b"});
    jp.setLayout(new BorderLayout());
              jp.add(jcb,BorderLayout.NORTH);
              jp.add(new JTextArea(),BorderLayout.CENTER);
    // create opaque glass pane
    JPanel glass = new JPanel();
    glass.setOpaque(false);
    // Attach modal behavior to frame
    modal.addInternalFrameListener(
    new ModalAdapter(glass));
    // Add modal internal frame to glass pane
    glass.add(modal);
    // Change glass pane to our panel
    frame.setGlassPane(glass);
    // Show glass pane, then modal dialog
    modal.setVisible(true);
    glass.setVisible(true);
    System.out.println("Returns immediately");
    JInternalFrame internal =
    new JInternalFrame("Opener");
    desktop.add(internal);
    JButton button = new JButton("Open");
    button.addActionListener(showModal);
    Container iContent = internal.getContentPane();
    iContent.add(button, BorderLayout.CENTER);
    internal.setBounds(25, 25, 200, 100);
    internal.setVisible(true);
    Container content = frame.getContentPane();
    content.add(desktop, BorderLayout.CENTER);
    frame.setSize(500, 300);
    frame.setVisible(true);
    private static void initLookAndFeel(String lookAndFeel) {
    String lookAndFeelClassName = null;
    UIManager.LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels();
    for(int i=0; i<lafInfo.length; i++) {
    if (lafInfo[i].getName().equals(lookAndFeel)) {
    lookAndFeelClassName = lafInfo[i].getClassName();
    if (lookAndFeelClassName == null)
    System.err.println("No class found for lookAndFeel: "+ lookAndFeel);
    try {
    UIManager.setLookAndFeel(lookAndFeelClassName);
    } catch (ClassNotFoundException e) {
    System.err.println("Couldn't find class for specified look and feel:"
    + lookAndFeel);
    System.err.println("Did you include the L&F library in the class path?");
    System.err.println("Using the default look and feel.");
    } catch (UnsupportedLookAndFeelException e) {
    System.err.println("Can't use the specified look and feel ("
    + lookAndFeel
    + ") on this platform.");
    System.err.println("Using the default look and feel.");
    } catch (Exception e) {
    System.err.println("Couldn't get specified look and feel ("
    + lookAndFeel
    + "), for some reason.");
    System.err.println("Using the default look and feel.");
    e.printStackTrace();

    Hi,
    Had exactly the same problem. Seems there are plenty of similar problems all related to the glass pane, so have solved the problem here by putting the event-blocking panel onto the MODAL_LAYER of the layered pane, rather than replacing the glass pane. Otherwise pretty much the same technique - you may need a property change listener to track changes in the size of the layered pane
    something like ...
    layer = frame.getLayeredPane();
    glass.setSize (layer.getSize()); // will need to track size
    glass.add (modal);
    layer.add(glass, JLayeredPane.MODAL_LAYER, 0);
    I've modified the original examples so the frames can be re-used so you may have to play around with the example a bit
    Hope it helps
    cheers.

  • How to execute windows application in Jinternal frame

    I want to execute windows application in a JInternal Frame ?

    Attach an EventListener and
    try{ Runtime.getRuntime().exec("C:\\Program Files\\Outlook Express\\ ..."); }
              catch(Exception e){}

  • JInternal frames.. please help

    Hi All,
    Can anyone tell me how to set JInternal frames as unmovable?
    I want to add it to a content pane and not alow the users to move it around,..
    Thanks

    hi,
    if i had to do the same i'd have followed the below coding.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.MouseEvent;
    public class Test extends JInternalFrame {
       // location variables to set the initial
       // location of the internalframe
       private int x;
       private int y;
       public Test(int x, int y)
          super("Sample", true, true, true, true);
          this.x = x;
          this.y = y;
          setLocation(Integer.MIN_VALUE, Integer.MAX_VALUE);
       public Test(Point loc)
          this(loc.x, loc.y);
       public Test()
          this(0, 0);
       /* Overriden method.
        * If this does'nt work then comment this method & uncomment
        * processMouseMotionEvent(MouseEvent) method.
       public void setLocation(int x, int y)
          super.setLocation(this.x, this.y);
       /* Overriden method.
        * If this does'nt work then comment this method & uncomment
        * processMouseMotionEvent(MouseEvent) method.
       public void setLocation(Point p)
          super.setLocation(this.x, this.y);
       public static void main(String args[])
          Test test = new Test();
          test.setSize(300, 300);
          JFrame frame = new JFrame("ATest");
          JDesktopPane pane = new JDesktopPane();
          frame.setContentPane(pane);
          pane.add(test);
          frame.pack();
          frame.show();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       /* Overriden method.
        * If the above setLocation methods does'nt stand to your
        * expectations, then you may try with the following method.
        * Note: You may risk the mouse dragging feature if you are
        *       implementing mouse dragging feature in the internal frame.
    /*   protected void processMouseMotionEvent(MouseEvent e)
          if(e.getID() == MouseEvent.MOUSE_DRAGGED)
             e.consume();
          } else
             super.processMouseMotionEvent(e);
    }though i've'nt tested the code, it should work smoothly. there might be more easier way to achieve what you want.
    hope this helps you,
    regards,
    Afroze.

  • How to add scrollbar to the JInternal Frame

    How to add scrollbar to JInternal Frame?
    I have One JInternal frame i want it should have a scrollbar when we reduces its size.

    [url http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html]How to Use Scroll Panes

  • Remove Focus from Main Frame after Jinternal Frame is opened.

    Hi,
    I want to restrict the user to change any thing on main frame once the JInternalFrame is opened (you can see same effect when we execute JOptionPane where focus on main is not retain untill you close the JOptionPane).
    I have written following code to listen the JInternalFrame event
    conn_prop.addInternalFrameListener(new InternalFrameListener(){
    @Override
    public void internalFrameActivated(InternalFrameEvent e) {
    // TODO Auto-generated method stub
    @Override
    public void internalFrameClosed(InternalFrameEvent e) {
    // TODO Auto-generated method stub
    @Override
    public void internalFrameClosing(InternalFrameEvent e) {
    // TODO Auto-generated method stub
    @Override
    public void internalFrameDeactivated(InternalFrameEvent e) {
    // TODO Auto-generated method stub
    @Override
    public void internalFrameDeiconified(InternalFrameEvent e) {
    // TODO Auto-generated method stub
    @Override
    public void internalFrameIconified(InternalFrameEvent e) {
    // TODO Auto-generated method stub
    @Override
    public void internalFrameOpened(InternalFrameEvent e) {
    // TODO Auto-generated method stub
    }}); I tried setEnabled(false) but this is paralyzing entire application
    what piece of code should i write to do that........
    thanks in advance.

    That is not how a JInternalFrame is meant to be used. Read the Swing tutorial on "Using Internal Frames".
    Use a modal JDialog.

  • Is it possible or not?(Modal Internal Frames)

    Hi,
    I am continously trying with Modal JInternalFrames.
    But I donot need JOptionPane.Because in that JInternalFrame I didnot ask any confirmation,Infirmation.That InternalFrame is help Frame with a JTabel containg all the records from the database.
    So When I viewing this help page I should block the remaining GUI to accept anything.After closing the Help JInternalFrame I have to work with remaining GUI. That is simply Modal JInternalFrame.
    Is it possible?
    I try with the approch given in the site
    http://java.sun.com/developer/JDCTechTips/2001/tt1220.html
    and also with vetoablechange listener.
    But I didnot get the proper result.That is I coulnot properly implement that.But I solve some errors during development and try my level best.But Not yet correct result.
    So will anybody give me some solutions ,links or some guidance to do that.
    It will very helpful to me.
    Thank you so much.
    Meena

    Here is what I am referring to. Let me know if you need more info.
    public class MyDialog extends JDialog{
       public MyDialog(){
            add(new JButton("Test");
            setModal(true);
    public class MyInternalFrame extends JInternalFrame{
       public void handleButtonPress(){
           MyDialog dialog = new MyDialog();
           dialog.setVisible(); // this will not return until dialog is closed.
    }

  • How to add a jpanel in a jtable in a Jinternal frame

    hi to all,
    I want to add a panel above the table,which has been created in an internal frame,in the internal frame.
    i have created the table within the internal frame but unable to add panel in it..
    thanks

    Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]How to Use Layout Managers. Mix and match layout managers to get the desired effect.

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

  • JInternal Frames

    Hi all, I am currently writing a program which should allow me to add, delete, search and edit database records. What i would like to do is to click one of the six buttons on the toolbar and it to lauch a form within an internal frame. I have had a go but a cannot make the frame viewable. If you could help me i would be very grateful. Cheers x
    package worldfactfile;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
    public class mainScreen extends JFrame implements ActionListener{
      JPanel contentPane, panel;
      private JDesktopPane theDesktop;
      private JButton button1, button2, button3, button4, button5, button6;
      BorderLayout borderLayout1 = new BorderLayout();
      XYLayout xYLayout1 = new XYLayout();
      JLabel jLabel1 = new JLabel();
      //Construct the frame
      public mainScreen() {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
          jbInit();
        catch(Exception e) {
          e.printStackTrace();
      //Component initialization
      private void jbInit() throws Exception {
        ImageIcon image1 = new ImageIcon("add.gif");
        ImageIcon image2 = new ImageIcon("edit.gif");
        ImageIcon image3 = new ImageIcon("delete.gif");
        ImageIcon image4 = new ImageIcon("search.gif");
        ImageIcon image5 = new ImageIcon("help.gif");
        ImageIcon image6 = new ImageIcon("exit.gif");
        button1 = new JButton(image1);
        button2 = new JButton(image2);
        button3 = new JButton(image3);
        button4 = new JButton(image4);
        button5 = new JButton(image5);
        button6 = new JButton(image6);
        button1.addActionListener(this);
        button6.addActionListener(this);
        JToolBar bar = new JToolBar();
        bar.add(button1);
        bar.add(button2);
        bar.add(button3);
        bar.add(button4);
        bar.add(button5);
        bar.add(button6);
        contentPane = (JPanel) this.getContentPane();
        contentPane.setLayout(borderLayout1);
        theDesktop = new JDesktopPane();
        contentPane.add("Center", theDesktop);
        contentPane.add("South", bar);
        this.getContentPane().setBackground(SystemColor.controlText);
        this.setSize(new Dimension(950, 750));
        this.setTitle("World Fact File");
        panel = new JPanel() {
                     public void paintComponent(Graphics g)     {
                             ImageIcon img = new ImageIcon("globe2.gif");
                             g.drawImage(img.getImage(), -20, -50, null);
                             super.paintComponent(g);
             panel.setOpaque(false);
        contentPane.add(panel);
      public void actionPerformed(ActionEvent e){
        if(e.getSource() == button6){
          System.exit(0);
        if(e.getSource() == button1){
          JInternalFrame iFrame = new JInternalFrame("My Frame, mine i said", true, true, true, true);
          JLabel lb1 = new JLabel("Hey ho...");
          iFrame.getContentPane().add(lb1);
          iFrame.setSize(new Dimension(200,50));
          iFrame.setVisible(true);
          theDesktop.add(iFrame);
      protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
    }

    here is ur code, i've modifyed some places. its working now.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class mainScreen extends JFrame implements ActionListener{
      JPanel contentPane, panel;
      JDesktopPane theDesktop;
      JButton button1, button2, button3, button4, button5, button6;
      BorderLayout borderLayout1 = new BorderLayout();
      //XYLayout xYLayout1 = new XYLayout();
      JLabel jLabel1 = new JLabel();
      //Construct the frame
      public mainScreen() {
        button1 = new JButton("One");
        button2 = new JButton("Two");
        button3 = new JButton("Three");
        button4 = new JButton("Four");
        button5 = new JButton("Five");
        button6 = new JButton("Six");
        button1.addActionListener(this);
        button6.addActionListener(this);
        JToolBar bar = new JToolBar();
        bar.add(button1);
        bar.add(button2);
        bar.add(button3);
        bar.add(button4);
        bar.add(button5);
        bar.add(button6);
        //contentPane = (JPanel) this.getContentPane();
        panel = new JPanel();
        panel.setLayout(borderLayout1);
        theDesktop = new JDesktopPane();
        panel.add("Center", theDesktop);
        panel.add("South", bar);
        getContentPane().add(panel);
        setSize(new Dimension(950, 750));
        setTitle("World Fact File");
        setVisible(true);
      public void actionPerformed(ActionEvent e){
        if(e.getSource() == button6){
          System.exit(0);
        if(e.getSource() == button1){
          JInternalFrame iFrame = new JInternalFrame("My Frame, mine i said", true, true, true, true);
          JLabel lb1 = new JLabel("Hey ho...");
          iFrame.getContentPane().add(lb1);
          iFrame.setSize(new Dimension(200,50));
          iFrame.setVisible(true);
          theDesktop.add(iFrame);
      protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
      public static void main(String a[]){
           mainScreen ms = new mainScreen();
    }

  • How to fix the position of JInternal frames added in JFrame

    Hay Frnds, I am having a problem. I have a JFrame ,in which i have added five JInternalFrames. My problem is that i want to fix the position of thaose Internal frames so that user cant move them from one place to other. Is there any way to fix there position. Plz reply as soon as possible. Its very urgent.
    Thanks.

    In Jframe I added one rootPanelI don't know what a rootPanel is or why you think you need to add one.
    The general code should probably be something like:
    frame.add(userPanel, BorderLayout.CENTER);
    frame.add(buttonPanel, BorderLayout.SOUTH);
    frame.pack();Read the section from the Swing tutorial on [Using Layout Managers|http://java.sun.com/docs/books/tutorial/uiswing/TOC.html] for more information and working examples.
    For more help create a [SSCCE (Short, Self Contained, Compilable and Executable, Example Program)|http://sscce.org], that demonstrates the incorrect behaviour.
    Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.

  • Setting the font of the titlebar of JInternal Frames??

    hi all,
    i am trying to change the font of the titles of JinternalFrames..
    i have tried it but cant p*** compilation..
    i have done.. title.setFont(X,X,X);
    is it possible to set the fonts of titlebars of frames?
    If i cant do it like this, is there another way around this?
    thank u ..

    If you tried it and it doesn't work, then that likely means they work the same as JFrames, where the title bar is rendered by the operating system and not by Java. If you are using Windows, that means you have to go into the Control Panel and adjust the Display properties to change the font.

  • Jtree leaf selection on jinternal frame

    Hi all,
    I m using a splitpane ...on left hand side i m using a tree and right side i m using a desktoppane where i'll open the internal frames...my tree leaf and internalframe title is same ...
    my question is when when i select any internalframe it should select corresponding leaf(becoz my leaf and t\internalframe is same)...and same i wanna do for tree when i click in any leaf ...internal frame should actived and come to front...
    pls can anyone tell me how to proceed for this...
    can anyone provide me any examples ....pls help me out
    regards
    Tarique

    Since you have a reference to a DefaultMutableTreeNode object, can't you do something like
    TreeNode[] nodes = n.getPath();
    TreePath path = new TreePath(nodes);
    tree.setSelectionPath(path);

  • Drawing in Jinternal frames

    I have a frame using a JDesktopPane and it contains
    a varying number of JInternalFrames.
    I just want to draw onto the
    JInternalFrames.
    Do i place a large JPanel as a child in the JInternalFrame class?
    To i draw directly to the desktop?

    I just want to draw onto the JInternalFrames.what exactly do you mean by this? do you want to draw 'inside' the frames or on top of all frames?
    Do i place a large JPanel as a child in the JInternalFrame class?if you want to draw inside the frame, yes
    To i draw directly to the desktop? if you want to draw on top the frames, yes
    be a bit more specific pls.

Maybe you are looking for

  • Removing spaces between cross tabs

    Hello... I created one cross tab with 10 rows and 2 columns(In Crosstab Expert). Based on grouping i got 5 set of cross tab reports,Each cross tab contains 4 records .But in between these crosstabs blank spaces are there ,How can i avoid such blank s

  • Jpg opens new browser window

    I am trying to drag and drop a scanned image into a website. The website application has java and is supposed to load the image into it. What happens instead is that the image opens its own browser window as if I am just trying to look at the image.

  • Cannot open CS6 Bridge.  Always the same ERROR: Bridge has a problem and cannot read the cache

    Cannot open CS6 Bridge.  Always the same ERROR: Bridge has a problem and cannot read the cache

  • Why won't iphoto send pictures

    When I try to send multiple pictures using the fun templates included with iphoto, an error message comes up every time saying "username and password not recognized by e-mail server."  this cannot be correct since I've since deleted and added both of

  • How best to manage Windows on a Retina Display?

    I'm running a Macbook Pro 15" Retina, set up with Windows 8.1 on a Boot Camp partition, that I also access from within Mac OS X Mavericks using Fusion 6 (whatever the current version is). This means I've spent a bit of time trying to sort out the fun