Access to an JInternalFrame

Hi,
I have a JFrame with aJDesktoPane. I want to access the current selected JInternalFrame from an "Edit" button within my JMenuBar in my JFrame.
Does anyone know, how to get the currently active JInternalFrame?

actionPerformed(ActionEvent e)
JInternalFrame[] allFrames = desktop.getAllFrames()
for(int i = 0, size = allFrames.length; i < size ; i++)
if(allFrames.isSelected())
System.out.println("the current selected frame is "+allFrames[i])
break;

Similar Messages

  • Please, URGENT! Access objects in JInternalFrame

    I need to access a specific object in a JInternal frame, e.g. a JTextField. I have different istance of the same JInternalFrame that contain a JTabbedPane with different pane. I use the getSelectedFrame() method to get the JInternalFrame handle of the focused JInternalFrame, but I don't know how to reference the JTextField contained in one of the pane contained in the JTabbedPane contained in the JInternalFrame.
    please help me soon

    well if the JInternal frame is in its own class file then in that same file make a method like
    public JTextArea getTextArea(){
    return this.<JTextArea>;
    that way you can access it like
    getSelectedFrame().getTextArea().setText("wadadadadadadadadada");
    or summin like that

  • Access and set title of JInternalFrame from contentPanel

    I know the answer is probably very easy but how do I dynamiically access and set the title of the JInternalFrame from a JPanel in the contentPane? The problem is the JPanel does not have a direct reference stored to the JInternalFrame

    Hi,
    Please try '''firefox -p -no-remote''' in the '''Start''' > '''Run''' box (or press windows key + '''R''' if the Run box is not present), delete all the profiles with the files in it and create a new one. Please also see [http://kb.mozillazine.org/Profile_folder_-_Firefox Firefox Profile Folder & Files] and [https://support.mozilla.com/en-US/kb/Backing%20up%20your%20information?s=backup&r=1&as=s Backup.]
    Useful links:
    [https://support.mozilla.com/en-US/kb/Options%20window All about Tools > Options]
    [http://kb.mozillazine.org/About:config Going beyond Tools > Options - about:config]
    [http://kb.mozillazine.org/About:config_entries about:config Entries]
    [https://addons.mozilla.org/en-US/firefox/addon/whats-that-preference/ What's That Preference? add-on] - Quickly decode about:config entries - After installation, go inside about:config, right-click any preference, enable (tick) MozillaZine Results to Panel and again right-click a pref and choose MozillaZine Reference to begin with.
    [https://support.mozilla.com/en-US/kb/Keyboard%20shortcuts Keyboard Shortcuts]
    [https://support.mozilla.com/en-US/kb/Viewing%20video%20in%20Firefox%20without%20a%20plugin Viewing video in Firefox without a plugin]
    [http://kb.mozillazine.org/Profile_folder_-_Firefox Firefox Profile Folder & Files]
    [https://support.mozilla.com/en-US/kb/Safe%20Mode Safe Mode]
    [https://support.mozilla.com/en-US/kb/Basic%20Troubleshooting Basic Troubleshooting]
    [http://kb.mozillazine.org/Problematic_extensions Problematic Extensions]
    [https://support.mozilla.com/en-US/kb/Troubleshooting%20extensions%20and%20themes Troubleshooting Extensions and Themes]
    [http://kb.mozillazine.org/Testing_plugins Testing Plugins]
    [https://support.mozilla.com/en-US/kb/Troubleshooting%20plugins Troubleshooting Plugins]

  • JInternalFrame drawing problem.

    Hi gurus
    Please could you help with a java problem that I cant find an answer to over the net:
    I have a JDesktop which contains multiple JInternalFrames. On one JInternalFrame i have attached a JPanel on which to draw on. I have multiple threads (simple ball shapes) that need to be drawn onto the JPanel and have left it up to the indivual threads to draw themselves (as opposed to using paintComponent in the JPanel class). The drawing on the JInternalFrame works perfectly fine.
    The problem arises when the other JInternalFrames are placed on top of each other - the balls are drawn over the top most JInternalFrame. What am i doing wrong? I have attached snippets of the code:
    public class Desktop extends JFrame implements ActionListener
              public Desktop()
                        setTitle("Agent's world");
                        setSize(w,h);
                        setDefaultCloseOperation(EXIT_ON_CLOSE);
                        JDesktopPane desktop = new JDesktopPane();
                        setContentPane(desktop);
                        /************* Agent *************/
                        JInternalFrame agents = new JInternalFrame("Agents War", true, false, true, false);                    
                        agents.reshape(0,0,(int)((w/3)*2),h);
                        Container contentPane = agents.getContentPane();
                        canvas = new AgentPanel(agents);
                        contentPane.add(canvas);
                        /************* Button *************/
                        JPanel buttonPanel = new JPanel();
                        ButtonGroup buttonGroup = new ButtonGroup();
                        JButton start = new JButton("START");
                        start.addActionListener(this);
                        buttonPanel.add(start);
                        contentPane.add(buttonPanel, "North");
                        agents.setVisible(true);
                        desktop.add(agents);
                        //sets focus to other frames within the desktop
                        try
                                  agents.setSelected(true);
                        catch(PropertyVetoException e)
                                  //attempt to refocus was vetoed by a frame
              /** Method to listen for event actions, i.e. button clicks **/
         public void actionPerformed(ActionEvent event)
                   //passes through 'this' to allow access to the getList method
                   Agents agent = new Agents(canvas, this);
                   agent.start();
    public class Agents extends Thread
              public Agents(AgentPanel panel, Desktop desktop)
                        panel =_panel;
                        desktop = _desktop;
                        setDaemon(true);
    /** Moves the agent from a spefic position to a new position **/
              public void move()
                        Graphics g = panel.getGraphics();
                        Graphics2D g2 = (Graphics2D)g;
                        try
                                  //set XOR mode
                                  g.setXORMode(panel.getBackground());
                                  //draw over old
                                  Ellipse2D.Double ballOld = new Ellipse2D.Double(i , j, length, length);
                                  g2.fill(ballOld);     
                                  i++;
                                  j++;
                                  if(flag == true)
                                            //draw new
                                            Ellipse2D.Double ballNew = new Ellipse2D.Double(i , j, length, length);
                                            g2.fill(ballNew);
                                            g2.setPaintMode();
                        finally
                                  g.dispose();
              /** Activates the Thread **/
              public void run()
                   int i = 0;
                   while(!interrupted() && i<100)
                        try
                                       for(i = 0 ; i <100 ; i++)
                                                 //draw ball in old position                                             move();          
                                                 sleep(100);                              
                             catch(InterruptedException e)
    public class AgentPanel extends JPanel
              /** local copy of internal frame */
              private JInternalFrame frame;
              public AgentPanel(JInternalFrame _frame)
                        frame = _frame;
                        setSize(frame.getWidth(), frame.getHeight());
                        setBackground(Color.white);          
              public void paintComponent(Graphics g)
                        super.paintComponent(g);
    Thank you in advance.
    Ravs

    I have the same problem. Seems to be a bug. See:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=231037
    Bummer.

  • Undecorated JInternalFrame becomes decorated by itself.

    Hi,
    I’m facing a problem with JInternalFrame implementation. I have made the JInternalFrame undecorated, so that the title bar and border of the JInternalFrame gets removed. The problem occurs in the following scenario.
    *1)     Execute the program in a Windows 7 machine.*
    *•     At this point the JInternalFrame remains undecorated.*
    *2)     Access the Windows 7 machine using remote desktop sharing from another machine.*
    *•     Now the title bar and border of the internal frame becomes visible.*
    This issue occurs only in Windows 7 machine, and not in Windows XP. You can access the Windows 7 machine using remote desktop sharing from another Windows 7 machine or Windows XP machine.
    Also if you access the machine using remote desktop sharing first, and then execute the program, the JInternalFrame remains undecorated.
    Steps to reproduce
    Step 1: Execute the application in a Windows 7 machine.
    Step 2: Access the Windows 7 machine using remote desktop sharing from another Windows 7 or Windows XP machine.
    Step 3: Check the GUI of the application
    Result :- The title bar and border of the undecorated JInternalFrame becomes visible.
    If anyone has faced this issue or if anyone has a solution for this issue, kindly share your thoughts.
    A sample code using which you can reproduce this issue is given below.
    * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    * - Redistributions of source code must retain the above copyright
    * notice, this list of conditions and the following disclaimer.
    * - Redistributions in binary form must reproduce the above copyright
    * notice, this list of conditions and the following disclaimer in the
    * documentation and/or other materials provided with the distribution.
    * - Neither the name of Oracle or the names of its
    * contributors may be used to endorse or promote products derived
    * from this software without specific prior written permission.
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
    * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    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 javax.swing.plaf.basic.BasicInternalFrameTitlePane;
    import javax.swing.plaf.basic.BasicInternalFrameUI;
    import java.awt.event.*;
    import java.awt.*;
    * InternalFrameDemo.java requires:
    * MyInternalFrame.java
    public class InternalFrameDemo extends JFrame
    implements ActionListener {
    JDesktopPane desktop;
    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);
    setJMenuBar(createMenuBar());
    //Make dragging a little faster but perhaps uglier.
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    protected JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    //Set up the lone menu.
    JMenu menu = new JMenu("Document");
    menu.setMnemonic(KeyEvent.VK_D);
    menuBar.add(menu);
    //Set up the first menu item.
    JMenuItem menuItem = new JMenuItem("New");
    menuItem.setMnemonic(KeyEvent.VK_N);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(
    KeyEvent.VK_N, ActionEvent.ALT_MASK));
    menuItem.setActionCommand("new");
    menuItem.addActionListener(this);
    menu.add(menuItem);
    //Set up the second menu item.
    menuItem = new JMenuItem("Quit");
    menuItem.setMnemonic(KeyEvent.VK_Q);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(
    KeyEvent.VK_Q, ActionEvent.ALT_MASK));
    menuItem.setActionCommand("quit");
    menuItem.addActionListener(this);
    menu.add(menuItem);
    return menuBar;
    //React to menu selections.
    public void actionPerformed(ActionEvent e) {
    if ("new".equals(e.getActionCommand())) { //new
    createFrame();
    } else { //quit
    quit();
    //Create a new internal frame.
    protected void createFrame() {
    MyInternalFrame frame = new MyInternalFrame();
    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.
    InternalFrameDemo frame = new InternalFrameDemo();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Display the window.
    frame.setVisible(true);
    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();
    /* Used by InternalFrameDemo.java. */
    @SuppressWarnings("serial")
    class MyInternalFrame extends JInternalFrame {
    static int openFrameCount = 0;
    static final int xOffset = 30, yOffset = 30;
    public MyInternalFrame() {
    super("Document #" + (++openFrameCount),
    true, //resizable
    true, //closable
    true, //maximizable
    true);//iconifiable
    //...Create the GUI and put it in the window...
    //...Then set the window size or call pack...
    setSize(300,300);
    // Undecorating the internal frame
    BasicInternalFrameTitlePane titlePane =
    (BasicInternalFrameTitlePane) ((BasicInternalFrameUI) this.getUI()).
    getNorthPane();
    this.remove(titlePane);
    this.setBorder(null);
    //Set the window's location.
    setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
    }

    Thanks a lot for that lead Walter.
    Actually when I tried to override updateUI(), I got a NullPoinerException. Instead of that, I tried overriding the paintComponent() method, did the undecoration part in that method and, and called super.paintComponent(g) inside the method. Then the issue was resolved.
    Once again, thanks for the quick reply.

  • A question on JInternalFrame of Swing. Let see the code

    Hello everybody,
    I am setting up a Frame that contains 2 JInternalFrames in its desktopPane. The first JInternalFrame is to show the map. The second one have some check box. What I wanna do is, when I check the CheckBox in the second JInternalFrame, after getting the result from Database, it show the result on Map. The result will be some red ellipses on the first JInternalFrame.
    The code work well with Database. But I really need your help to do with the event on InternalFrame
    Thanks in advance !
    Quin,
    Here is the code of the main Frame:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.font.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.util.*;
    import java.io.*;
    import java.net.*;
    import java.beans.*;
    public class MapLocator
         public static void main(String [] args)
              JFrame frame = new DesktopFrame();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setVisible(true);
    Create a desktop frames that contains internal frame
    class DesktopFrame extends JFrame implements ActionListener
         public DesktopFrame()
              super("Map Locator v.1.0.0");
              this.setSize(new Dimension(WIDTH,HEIGHT));
              desktop = new JDesktopPane();
              this.setContentPane(desktop);
              this.createInternalFrame(
                   new mapPanel(),"Ban do Thanh pho Ho Chi Minh",0,0,480,515);
              this.createInternalFrame(
                   new commandPanel(),"Chu thich va tim kiem",480,0,320,515);
    Create an internal frame on the desktop.
    @param c the component to display in the internal frame
    @param t the title ofthe internal frame.
         public void createInternalFrame(JPanel c, String t,int ifx, int ify, int ifwidth, int ifheight)
                 final JInternalFrame iframe = new JInternalFrame(t,
                 true//resizeable
                 ,true//closable
                 ,true//maximizable
                 ,true//iconifiable
                 iframe.getContentPane().add(c);
                 desktop.add(iframe);
                 iframe.setFrameIcon(new ImageIcon("new.gif"));
                 //add listener to confirm frame closing
                 iframe.addVetoableChangeListener(new VetoableChangeListener()
                      public void vetoableChange(PropertyChangeEvent event)
                           throws PropertyVetoException
                           String name = event.getPropertyName();
                           Object value = event.getNewValue();
                           //we only want to check attempts to close a frame
                           if(name.equals("closed") && value.equals(Boolean.TRUE))
                                //ask user if it is ok to close
                                int result =
                      JOptionPane.showInternalConfirmDialog(iframe,"OK to close");
                                //if the user doesn't agree, veto the close
                                if(result != JOptionPane.YES_OPTION)
                      throw new PropertyVetoException("User cancel the close",event);
                 iframe.setVisible(true);
                 iframe.setLocation(ifx,ify);
                 iframe.setSize(new Dimension (ifwidth, ifheight));
         private static final int WIDTH = 800;
         private static final int HEIGHT = 600;
         private JDesktopPane desktop;
         private int nextFrameX;
           private int nextFrameY;
            private int frameDistance;
         private JMenuBar menuBar;
         private JMenu fileMenu, viewMenu, searchMenu, windowMenu, helpMenu;
         private JRadioButtonMenuItem javalaf, liquidlaf, motiflaf, windowlaf, threedlaf;
    }Below is the code of first JInternalFrame
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.sql.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import java.util.Random;
    import java.util.*;
    import com.sun.image.codec.jpeg.*;
    Create a canvas that show a map
    public class mapPanel extends JPanel
         implements MouseMotionListener, MouseListener
         public mapPanel()
              addMouseMotionListener(this);
              addMouseListener(this);
    Unbarrier the comment below to see how the map model work
    //Unbarrier this to see -->
             try
                InputStream in = getClass().getResourceAsStream(nameOfMap);
                JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);
                mImage = decoder.decodeAsBufferedImage();
                in.close();//Close dong nhap
              catch(ImageFormatException ie)
              { System.out.println ("Error on formating image");}
              catch(IOException ioe)
              { System.out.println ("Error on input/ouput image");}
              catch(Exception e){}
    Connect to database
              connDB();
              String addQuery = "";
              try
              Get the relation amongs points
                   int idStart = 0;
                   int idEnd = 0;
                   addQuery ="SELECT IDStart, IDEnd FROM 2Diem";
                   rs = stmt.executeQuery(addQuery);
                   int incre = 0;
                   while(rs.next())
                        idStart = rs.getInt(1);
                        Rel.add(incre, new Integer(idStart));
                        incre ++;
                        idEnd = rs.getInt(2);
                        Rel.add(incre, new Integer(idEnd));
                        incre ++;
         Load the Coordination of the points to hash table
                   int idPoint = 0;
                   int XP = 0;
                   int YP = 0;
                   addQuery ="SELECT IDDiem, CoorX, CoorY FROM Diem";
                   rs = stmt.executeQuery(addQuery);     
                   while(rs.next())
                        idPoint = rs.getInt(1);
                        XP = rs.getInt(2);
                        YP = rs.getInt(3);
                        hashX.put(new Integer(idPoint), new Integer(XP));
                        hashY.put(new Integer(idPoint), new Integer(YP));
         Create Points to draw the Line
                   line = new Line2D[(Rel.size())/2];
                   for(int i = 0, k = 0; i < Rel.size();i++, k = k+2)
                        X1 = Integer.parseInt(""+hashX.get(Rel.elementAt(i)));
                        Y1 = Integer.parseInt(""+hashY.get(Rel.elementAt(i)));
                        i++;
                        X2 = Integer.parseInt(""+hashX.get(Rel.elementAt(i)));
                        Y2 = Integer.parseInt(""+hashY.get(Rel.elementAt(i)));
                        line[k/2] = new Line2D.Double(X1,Y1,X2,Y2);
              catch(SQLException sqle){}
         private Hashtable hashX = new Hashtable();
         private Hashtable hashY = new Hashtable();
         private Vector Rel = new Vector(100,10);
         private Vector vecBackX = new Vector(10,2);
         private Vector vecBackY = new Vector(10,2);
         private int X1 = 0, X2 = 0, Y1 = 0, Y2 = 0;
         Draw the image to show
         public void paintComponent(Graphics g)
              super.paintComponent(g);
              Graphics2D g2 = (Graphics2D) g;
              g2.setRenderingHint(
                   RenderingHints.KEY_ANTIALIASING,
                   RenderingHints.VALUE_ANTIALIAS_ON);
        //     g2.drawImage(mImage,0,0,null);
        Paint the background with light Gray
              g2.setPaint(Color.lightGray);
              g2.fill(new Rectangle2D.Double(0,0,480,480));          
             fillBack(g2);
        Draw the street with its border is white, its background is orange
             g2.setPaint(Color.white);
              g2.setStroke(new BasicStroke(14,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
              for(int k = 0; k < Rel.size()/2; k++)
                   g2.draw(line[k]);
              g2.setPaint(Color.orange);
              g2.setStroke(new BasicStroke(10,BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
              for(int k = 0; k < Rel.size()/2; k++)
                   g2.draw(line[k]);
         Draw the grid on map
              g2.setPaint(Color.white);
              g2.setStroke(new BasicStroke(1));
              drawGrid(g2);
              if(point != null)
                   g2.setPaint(Color.red);
                   g2.fillOval(point.x - 3, point.y - 3, 7, 7);
    Draw the Background with tree and water
    @param g2 the Graphics2D that used to draw shapes
         private void fillBack(Graphics2D g2)
              Draw the background for map
              try
                   int BackX = 0;
                   int BackY = 0;
                   int incre = 0;
                   backGround = new GeneralPath[3];
                   for(int idBack = 1; idBack <= 3; idBack++)
    Since we use the vector for each background(tree / water), we have to
    refresh the vector before it can add new path inside
                        vecBackX.clear();
                        vecBackY.clear();
                        String addQuery = "SELECT CoorX, CoorY FROM BackCoor WHERE "
                        + " IDBack =" + idBack;
                        rs = stmt.executeQuery(addQuery);
                        while(rs.next())
                             BackX = rs.getInt(1);
                             BackY = rs.getInt(2);
    This will take the point into vector
                             vecBackX.add(incre,new Integer(BackX));
                             vecBackY.add(incre,new Integer(BackY));
                             incre++;
    Design the shapes of path
                             backGround[(idBack - 1)] =
                                  new GeneralPath(GeneralPath.WIND_EVEN_ODD);
                             backGround[(idBack - 1)].moveTo(
                                  Integer.parseInt(""+vecBackX.elementAt(0)),
                                  Integer.parseInt(""+vecBackY.elementAt(0)));
                             for(int i = 1; i < vecBackX.size(); i++)
                                  backGround[(idBack - 1)].lineTo(
                                       Integer.parseInt(""+vecBackX.elementAt(i)),
                                       Integer.parseInt(""+vecBackY.elementAt(i)));
                             backGround[(idBack - 1)].lineTo(
                                       Integer.parseInt(""+vecBackX.elementAt(0)),
                                       Integer.parseInt(""+vecBackY.elementAt(0)));
                             backGround[(idBack - 1)].closePath();
    Here we have 3 Path that represented to tree and water
    The first and second one is tree.
    The last one is water.
    Draw the path now
                             if(idBack == 3)
                                  g2.setPaint(Color.cyan);
                                  g2.fill(backGround[(idBack - 1)]);
                             else
                                  g2.setPaint(Color.green);
                                  g2.fill(backGround[(idBack - 1)]);
                             incre = 0;
              catch(SQLException sqle)
                   System.out.println ("Khong ve duoc back ground");
    Create the grid on map
    @param g2 the Graphics2D that used to draw shapes
         private void drawGrid(Graphics2D g2)
              try
                 String Query =
                 "SELECT * FROM Grid";
                 rs = stmt.executeQuery(Query);
                 GridX = new Vector(100,2);
                 GridY = new Vector(100,2);
                 GridW = new Vector(100,2);
                 GridH = new Vector(100,2);
                 int incr = 0;
                 while(rs.next())
                      gridX = rs.getInt(2);
                      gridY = rs.getInt(3);
                      gridW = rs.getInt(4);
                      gridH = rs.getInt(5);
                      GridX.add(incr, new Integer(gridX));
                      GridY.add(incr, new Integer(gridY));
                      GridW.add(incr, new Integer(gridW));
                      GridH.add(incr, new Integer(gridH));
                      incr ++;
                 rec = new Rectangle2D.Double[GridX.size()];
                 for(int i = 0; i < GridX.size(); i++)
                      gridX = Integer.parseInt(""+GridX.elementAt(i));
                      gridY = Integer.parseInt(""+GridY.elementAt(i));
                      gridW = Integer.parseInt(""+GridW.elementAt(i));
                      gridH = Integer.parseInt(""+GridH.elementAt(i));
                      rec[i] = new Rectangle2D.Double(gridX, gridY, gridW, gridH);
                      g2.draw(rec);
    catch(SQLException sqle){}
    private Vector GridX, GridY, GridW, GridH;
    private int gridX = 0, gridY = 0, gridW = 0, gridH = 0;
    Fill the point
         public void placePoint(Graphics2D g2,Point p)
              g2.setPaint(Color.red);
              g2.fill(new Ellipse2D.Double(p.x - 3, p.y - 3, 7,7));
    Create connection to Database
         public void connDB()
              System.out.println ("Connecting to Database");
              String fileName = "Pro.mdb";
              String data = "jdbc:odbc:Driver={Microsoft Access Driver " +
         "(*.mdb)};DBQ=" + fileName + ";DriverID=22";
              try
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   conn = DriverManager.getConnection(data,"","");
                   stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                        ResultSet.CONCUR_UPDATABLE);
              catch(ClassNotFoundException ce)
              { System.out.println ("Khong tim thay Driver"); }
              catch(SQLException sqle)
              { System.out.println ("Loi SQL trong khi Connect"); }
              Statement stmt = null;
              ResultSet rs = null;
              Connection conn = null;     
    This one is the model map to draw
         private String nameOfMap = "map.jpg";
         private BufferedImage mImage;
    Initialize the path and shapes to draw
         private Line2D line[];
         private Rectangle2D.Double rec[];
         private GeneralPath backGround[];
         private Point point;
         private int changeColor = 0;
    The last one is:
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.sql.*;
    public class commandPanel extends JPanel implements ActionListener
    Initial check box
         JCheckBox uyBanNhanDan = new JCheckBox();
         JCheckBox nganHang = new JCheckBox();
         JCheckBox buuDien = new JCheckBox();     
         JCheckBox khachSan = new JCheckBox();     
         JCheckBox benhVien = new JCheckBox();          
         JCheckBox cho = new JCheckBox();     
         JCheckBox nhaHat = new JCheckBox();     
         JCheckBox daiHoc = new JCheckBox();     
         JCheckBox thuvien = new JCheckBox();     
         JCheckBox nhaTho = new JCheckBox();     
         public commandPanel()
              this.setLayout(new BorderLayout());
              this.setBorder(BorderFactory.createCompoundBorder(
                          BorderFactory.createTitledBorder("***Chu dan***"),
                          BorderFactory.createEmptyBorder(5,5,5,5)));
    Create the combobox to show information
              uyBanNhanDan.setText("Uy Ban ND Quan");
              nganHang.setText("Ngan Hang");
              buuDien.setText("Buu Dien");
              khachSan.setText("Khach San");
              benhVien.setText("Benh Vien");
              cho.setText("Cho - Mua Sam");
              nhaHat.setText("Nha Hat");
              daiHoc.setText("Dai Hoc - Dao Tao");
              thuvien.setText("Thu Vien - Nha Sach");
              nhaTho.setText("Nha Tho - Chua");
              uyBanNhanDan.addActionListener(this);
              nganHang.addActionListener(this);
              buuDien.addActionListener(this);
              khachSan.addActionListener(this);
              benhVien.addActionListener(this);
              cho.addActionListener(this);
              nhaHat.addActionListener(this);
              daiHoc.addActionListener(this);
              thuvien.addActionListener(this);
              nhaTho.addActionListener(this);
              uyBanNhanDan.setActionCommand("1");
              nganHang.setActionCommand("2");
              buuDien.setActionCommand("3");
              khachSan.setActionCommand("4");
              benhVien.setActionCommand("5");
              cho.setActionCommand("6");
              nhaHat.setActionCommand("7");
              daiHoc.setActionCommand("8");
              thuvien.setActionCommand("10");
              nhaTho.setActionCommand("11");
              JPanel secP = new JPanel();
              secP.setLayout(new GridLayout(5,2));
              secP.add(uyBanNhanDan);
              secP.add(nganHang);
              secP.add(buuDien);
              secP.add(khachSan);
              secP.add(benhVien);
              secP.add(cho);
              secP.add(nhaHat);
              secP.add(daiHoc);
              secP.add(thuvien);
              secP.add(nhaTho);
              this.add(secP,BorderLayout.NORTH);
         public void actionPerformed(ActionEvent event)
              int x = 0;
              int y = 0;
              try
                   mapPanel mp = new mapPanel();
                   int idDiaDanh = 0;
                   if(event.getActionCommand() == "1")
                        idDiaDanh = 1;
                   String Query =
                   "SELECT CoorX, CoorY FROM MoTa WHERE IDDiaDanh =" + idDiaDanh;
                   mp.rs = mp.stmt.executeQuery(Query);
                   while(mp.rs.next())
    /*I have problem here*/
    /*Process the event for me*/          x = mp.rs.getInt(1);
                        y = mp.rs.getInt(2);
                        Graphics g2 = mp.getGraphics();
                        mp.paintComponents(g2);
                             g2.setPaint(Color.red);
                             g2.fill(new Ellipse2D.Double(x - 3, y - 3, 7, 7));     
              catch(SQLException sqle){}

    Strings are Objects.
    String[] strings = new String[3];
    String[0]="abcde";Right here, you are initializing the String array, and the String at index 0.
    JButton[] buttons = new JButton[2];
    buttons[0].setText("abcde");Right here, you are initializing the JButton array, but not any of the JButtons in the array. You then try to use the setText() method on a null JButton.

  • Communicate between two JInternalFrames

    Hello all.
    I have a swing application where I have a JFrame that encompasses two JInternalFrame's.
    We'll call them AppFrame, IFrame and StatusFrame
    I am attempting to create a running log of messages (Strings) that will be shown in StatusFrame.
    The IFrame will be generating these messages that need to show up on StatusFrame.
    Both are invoked by AppFrame.
    My question is: How do I pass the message from IFrame to StatusFrame? I imagine it will involve some object sharing, but my brain is fried.
    If anyone could point me in the right direction, I would appreciate it.
    Thanks!

    Thanks for bringing me up to speed!
    Just a couple of questions...please forgive me, I am very new to homegrowing listeners.
    1) When you said "which should save off the listener in some collection", how would you go about taking StatusListener listener and storing it, and, how do I access it to send a status? Do I access it by using:
    listener.statusChanged("message")?
    2) When you say "use the addStatusListener method of the iframe to add itself", just for clarification, I assume you mean something to the effect of:
    iframe.addStatusListener(statusFrame) , right?
    Again, thank you for helping me understand. I'm not quite there, but I am a lot further than I was yesterday.
    Message was edited by:
    nawlej

  • Accessing Members in Another Class

    How would I access a member from another class? In the actionPerformed method, I want to be able to access objects such as filemenu in the Main class. Here's most of my code:
    class fileEvent implements ActionListener
    {     public void actionPerformed(ActionEvent e,JMenuItem& item)
    public class Main extends JFrame implements ActionListener, ItemListener {
        /** Creates a new instance of Main */
        public Main() {
            this.setTitle("Cross-platform Map Editor");
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JInternalFrame drawingframe;
            JDesktopPane desk;
            JPanel drawingpanel = new JPanel();
            JMenuBar menubar = new JMenuBar();
            JMenu filemenu = new JMenu("File");
            JMenu editmenu = new JMenu("Edit");
            JMenu mapmenu = new JMenu("Map");
            JMenu tilesmenu = new JMenu("Tiles");
            JMenu toolsmenu = new JMenu("Tools");
            JMenu windowmenu = new JMenu("Window");
            JMenu aboutmenu = new JMenu("Help");
            JMenuItem fileItem1 = new JMenuItem("New...",KeyEvent.VK_N);
            fileItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.ALT_MASK));
            fileItem1.addActionListener(new fileEvent(),fileItem1);
            JMenuItem fileItem2 = new JMenuItem("Open...");
            JMenuItem fileItem3 = new JMenuItem("Save");
            JMenuItem fileItem4 = new JMenuItem("Save As...");
            JMenuItem fileItem5 = new JMenuItem("Exit");
            JMenuItem editItem1 = new JMenuItem("Undo");
            JMenuItem editItem2 = new JMenuItem("Redo");
            JMenuItem editItem3 = new JMenuItem("Cut");
            JMenuItem editItem4 = new JMenuItem("Copy");
            JMenuItem editItem5 = new JMenuItem("Paste");
            JMenuItem editItem6 = new JMenuItem("Select All");
            filemenu.add(fileItem1);
            filemenu.add(fileItem2);
            filemenu.add(fileItem3);
            filemenu.add(fileItem4);
            filemenu.add(fileItem5);
            editmenu.add(editItem1);
            editmenu.add(editItem2);
            editItem2.add(new JSeparator());
            editmenu.add(editItem3);
            editmenu.add(editItem4);
            editItem4.add(new JSeparator());
            editmenu.add(editItem5);
            menubar.add(filemenu);
            menubar.add(editmenu);
            menubar.add(mapmenu);
            menubar.add(tilesmenu);
            menubar.add(toolsmenu);
            menubar.add(windowmenu);
            menubar.add(aboutmenu);
            this.setJMenuBar(menubar);
            JButton drawingbutton1 = new JButton("Pencil");
            JButton drawingbutton2 = new JButton("Line");
            JButton drawingbutton3 = new JButton("Paint Pucket");
            JButton drawingbutton4 = new JButton("Recntangle");
            JButton drawingbutton5 = new JButton("Filled Rectangle");
            drawingpanel.add(drawingbutton1);
            drawingpanel.add(drawingbutton2);
            drawingpanel.add(drawingbutton3);
            drawingpanel.add(drawingbutton4);
            drawingpanel.add(drawingbutton5);
            drawingframe = new JInternalFrame("Drawing", true,true,true,true);
            drawingframe.add(drawingpanel);
            drawingframe.setSize(200,300);
            drawingframe.setVisible(true);
            desk = new JDesktopPane();
            desk.add(drawingframe);
            this.add(desk);
            this.setSize(500,500);
            this.setVisible(true);
    /code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    You don't want your Main class to have accessor methods or public variables... that's the worst dependency you can have.
    Anyways, think in terms of objects. When one object has a reference to another object, it can access all of its public data and methods.
    I'd recommend reading up on the basics:
    http://java.sun.com/docs/books/tutorial/java/index.html

  • Using BC4J in JInternalFrame

    Hello.
    I have been working a little with BC4J in Form (JFrame) and it works , now I want to use JInternalFrame ina JDesktopPane.
    I created a JFrame from JClient wizard and instead extends JFrame I modified the code to extends from JInternalFrame, also comment the constructor because don have listener, but when I want to put some Data Control from de palette , I dont have option to do it.
    Could anybody help me please? thanks a lot!

    Hello, thanks for the help, I do exactly what you say. Well now the situation is when I want to close the internalFrame in the case that JFrame there is no problem because it close with System.exit(0) but when I try to close an internalframe I get a problem. I use an JFrame that implements InternalFrameListener and invoke an Internalframe called MyInternalFrameUsuarios now, when I close the internalFrame I put in the listener of closing :
    public void internalFrameClosing(InternalFrameEvent e) {
    System.out.println("Internal frame closing");
    MyInternalFrameUsuarios finalFrame = (MyInternalFrameUsuarios)e.getInternalFrame();
    int action = finalFrame._popupTransactionDialog();
    if (action != JOptionPane.CLOSED_OPTION)
    finalFrame.panelBinding.releaseDataControl();
    //System.exit(0);
    I comment the System.exit because just want to close the internalFrame but the problem is that the window dont close, the content gone but the window still remain in the frame and if I try to close again the window I receive this exception :
    oracle.jbo.common.ampool.ApplicationPoolException: JBO-30006: The cookie for session AppModuleDataControl:1089132867566:1 and application AppModuleDataControl is not a valid handle for application pool, mypackage1.AppModuleLocal. The cookie may not be used to access this pool instance.
         at oracle.jbo.common.ampool.ApplicationPoolImpl.validateSessionCookieInPool(ApplicationPoolImpl.java:3001)
         at oracle.jbo.common.ampool.ApplicationPoolImpl.useApplicationModule(ApplicationPoolImpl.java:2541)
         at oracle.jbo.common.ampool.SessionCookieImpl.releaseApplicationModule(SessionCookieImpl.java:714) . ...
    Also if I open new internalFrame window and try to close the new one, this exception is generated :
    oracle.jbo.NameClashException: JBO-25001: Name MyInternalFrameUsuariosUIModel of object type Form Binding Definition already exists
         at oracle.adf.model.binding.DCDataControl.addOrCreateBindingContainer(DCDataControl.java:841)
         at oracle.adf.model.binding.DCDataControl.addBindingContainer(DCDataControl.java:788)
         at oracle.adf.model.binding.DCDataControl.addBindingContainer(DCDataControl.java:723)
         at oracle.adf.model.binding.DCBindingContainer.setDataControl(DCBindingContainer.java:274)
         at oracle.jbo.uicli.jui.JUPanelBinding.initializeApplicationModule(JUPanelBinding.java:261)
         at oracle.adf.model.binding.DCBindingContainer.getDataControl(DCBindingContainer.java:210) ....
    Thanks a lot for your help!!

  • Adding a button to a JInternalFrame titlebar

    hi ,
    i was looking for a way to add an additional button to the titlbar of my JInternalFrame , i found some very useful codes here but i still got a little problem , after i added the new button the title of my JInternalFrame becomes "..."
    i would like to hear any suggestion you guys have ,
    here is my code :
    import javax.swing.*;
    import javax.swing.plaf.basic.BasicInternalFrameUI;
    import javax.swing.plaf.metal.MetalInternalFrameTitlePane;
    import java.awt.*;
    public class InternalFrameTest extends JFrame{
        public InternalFrameTest() {
            super();
            JInternalFrame jInternalFrame = new JInternalFrame("InternalFrameTest",true,true,true,true);
            myTitleBar(jInternalFrame);
            jInternalFrame.setSize(400,400);
            jInternalFrame.setVisible(true);
            JDesktopPane desktop = new JDesktopPane();
            desktop.add(jInternalFrame);
            getContentPane().add(desktop);
            setSize(500, 500);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setLocationRelativeTo(null);
            setVisible(true);
        private void myTitleBar(JInternalFrame internalFrame){
            BasicInternalFrameUI basicInternalFrameUI = (BasicInternalFrameUI)internalFrame.getUI();
            MetalInternalFrameTitlePane northPane = (MetalInternalFrameTitlePane)basicInternalFrameUI.getNorthPane();
            JButton iconifyButton = null;
            JButton maximizeButton = null;
            JButton closeButton = null;
            Component[] components = northPane.getComponents();
            for( int i=0; i < components.length; i++ ){
                if( components[i] instanceof JButton ){
                    if( i == 0 ){
                         iconifyButton= (JButton)components;
    }else if( i == 1 ){
    maximizeButton= (JButton)components[i];
    }else{
    closeButton= (JButton)components[i];
    northPane.remove( components[i] );
    //create the additional button
    JButton additionalButton = new JButton("+");
    additionalButton.setFont(new Font("Arial",Font.BOLD,9));
    additionalButton.setPreferredSize(new Dimension(14,14));
    additionalButton.setMargin(new Insets(0, 0, 0, 0));
    //create a new buttons panel
    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setOpaque(false);
    buttonsPanel.setMaximumSize(new Dimension(-1, 14));
    //adding the buttons to the buttons panel
    buttonsPanel.add(additionalButton);
    buttonsPanel.add(iconifyButton);
    buttonsPanel.add(maximizeButton);
    buttonsPanel.add(closeButton);
    //adding the panel to the north pane of the internal frame
    northPane.setLayout(new BorderLayout());
    northPane.add(buttonsPanel,BorderLayout.EAST);
    public static void main(String[] args) {
    new InternalFrameTest();
    thanks in advance ,
    oz

    In general, it is very bad practice to access internal structures of UI delegates. Every time you find yourself casting getUI() result to a specific class and accessing the internal components, you are digging a very nasty hole. In this case, just adding the button is not enough - the internal frame title pane has a custom layout manager that knows nothing about it.
    You will have to dig much deeper and create your own UI delegate for internal frames to handle all the cases (including theme support, rollover effects, layout and RTL). Another option is to use Substance LAF that provides an API to add custom buttons to title panes [1]. This example shows how to do this for top-level frames, but the same would work for internal frames as well.
    [1] https://substance.dev.java.net/docs/api/SetRootPaneCustomTitleButtons.html

  • How to access the control menu

    How to access the control menu(Restore,move,minimize,maximize,close) of JFrame and JInternalFrame can be accessed using Keyboard like in windows(Using space bar for any window we can access the control menu of that window in Windows OS).
    How to achieve this feature in Java for JFrame and JInternalFrame
    Any sample code will be helpful

    try search the forum with topic: control menu on-off

  • Enable/Disable JMenu in JFrame on click of button in JInternalFrame

    Hello there. Could anybody help me out of the situation?
    I am trying to enable/disable JMenu of JFrame on click of a button which is in JInternalFrame.
    I want to set JMenu(this is in JFrame).setEnable(true) in ActionPerformed() of JInternalFrame, but JFrame and JInternalFrame are the different classes and I do not know how I can access JMenu in main frame.
    How should I write something like mainframe.menu.setEnabled(true) from internal frame?
    For JInternalFrame window action, there is JInternalFrameListener, but this is not relevant for my situation because I am trying to control on click of a button.
    Can anybody suggest a solution?

    // Main Frame
    public class MainFrame extends JFrame
         public MainFrame()
              InternalFrame l_int = new InternalFrame(this);
                    //try to initiate internal frame like this
         public void activateMenu()
              menuBar.setEnabled(true);
         public static void main(String args[])
              MainFrame mainframe = new MainFrame();
    // Internal Frame
    public class InternalFrame extends JInternalFrame
         private MainFrame m_mainFrm = null;
         public InternalFrame(MainFrame a_objMainFrame)
              //your own code
              m_mainFrm = a_objMainFrame;
         public void actionPerformed(ActionEvent a_objevent)
    if(m_mainFrm != null)
              m_mainFrm.activateMenu();
    }try this.. hope this will help you
    :)

  • How can access a data member in constructor

    hello,
    I want to know that How can access data member of class in constructor of same class
    Thnx
    Rakesh

    You need to point it at
    some object, like you do in newFile. What's in
    newFile is fine, but newFile isn't called beforethe
    doc= line.actually i have this a bigger program what i have
    send before. i m getting a object of JEditorPane in
    newFile() and asssigning it to epMain.
    Thats why i want to access epMain's that value what i
    have setted in newFile so i dont created a new object
    and assigned in epMain as like
    this.epMain= new JEditorPane();so how I can access epMain's that value what i have
    setted in newFile()
    here is actual newFile method
    public void newFile()
    Component comp=newEditPane();
    JInternalFrame iFrame=makeIF(comp,"Untitled");
    iFrame.setVisible(true);
    if(iFrame.getDesktopPane().getSelectedFrame()!=null)
    selectedFr=iFrame.getDesktopPane().getSelectedFrame();
    Container iContent = selectedFr.getContentPane();
    JScrollPane
    jsp=(JScrollPane)iContent.getComponent(0);
    JEditorPane
    e=(JEditorPane)jsp.getViewport().getView();
    this.epMain=e;
    Hmmn... Rakesh you're so makulit. Do you know what null pointer means? Here read the docs API,
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/NullPointerException.html
    You're displaying html using JEditorPane, why dont you try org.jdesktop.jdic.browser.WebBrowser?
    http://java.sun.com/developer/JDCTechTips/2005/tt0505.html
    Okie? ^_^
    -Ronillo.

  • Running Commands in JInternalFrame from DesktopPane

    I have a desktop Pane and within it, I am successfuly able to run various JInternal Frames.
    The DesktopPane has its own menu bar and the JInternal Frame has it's own Menu Bar. This has a very bad look on the overall appearance of the package.
    I want to combine both of these menu bars so that it appears on the DesktopPane.
    But I am odds at figuring out how to run a particular command from the menu bar of the desktop pane (like inserting an image inside the text pane in the Internal Frame)
    Any suggestions on where I should start?

    hello,
    just as poop said, create an object of the active frame by
    JInternalFrame frame = desktopPane.getSelectedFrame();//create an object of the active frameonce u have the object u can access its variables and methods as long as they are not protected (encapsulated). use the dot notation to access the variables or methods, i.e. frame.someVariable; or frame.someFunction();
    the other way (which is not so efficient) is by creating an interface file, store all variables used in the application there and implement the interface in all files, that way u can access the variables as well as methods but just as i said this method is not so efficient, it can work as a workaround.
    hope makes sense.
    asrar

  • Simple JInternalFrame question.

    Pro's,
    Would there be any reason why a JInternalFrame would not show up when accessed through a mouse click on a menu. I can bring it up perfectly when running it as a stand alone JFrame. It is not showing up when I change it to a JInternalFrame. I know and understand that the problem is while changing it from a JFrame to a JInternalFrame but I want to pin point it..:( and know what I need to make the JInternalFrame work the same as a JFrame. I searched the archives and 'googled' about the problem but could not find anything. Any suggestions/input will be very helpful. TIA.
    Misty.

    Thanks a lot for your response camickr
    JFrames are displayed on a desktop.Yes, makes sense.
    JInternalFrames are added to JDesktopPaneAlready did that.
    The desktop pane is added to your JFrameYes.
    I am still not able to display my JInternalFrame...Just does not make sense. Will keep trying away.
    Thanks again for the input.
    Misty.

Maybe you are looking for