InternalFrame and FocusListener

Hi All,
Please help me.
I have a Main Frame and a text field component in it, when i click on the text field i will open a internal frame, and this works fine. Now my requirement is when i click again outside the internal frame i.e anywhere on the main frame, the internal frame should be hidden, I implemented this using MouseListener, i handled mouseClicked method to do this. Problem in I too have a ImageButton on the main frame, and am not able to get mouseClicked method executed when clicked on that Image Button. what may the issue? Or please suggest me the best approach for this

when i click on the text field i will open a internal frameInternal frames should only be added to a JDesktopPane. They should not be used as a popup window.
Use a JDialog. You can then use a WindowListener and handle the windowDeactivated() event.

Similar Messages

  • Default background color and Focuslistener disapair on table?

    When I imp. TableCellRenderer on my table the default background color and Focuslistener disapair. What can I do to get it back and still keep TableCellRenderer on my table? This is how my TableCellRenderer looks:
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
            JFormattedTextField beloeb = new JFormattedTextField();
            beloeb.setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter()));
            beloeb.setBorder(null);
            beloeb.setHorizontalAlignment(JTextField.RIGHT);
            if (value != null) {
                if (value instanceof Double) {
                    Double val = (Double) value;
                    beloeb.setValue(val);
                    if (val.doubleValue() < 0) {
                        beloeb.setForeground(Color.RED);
            beloeb.setFont(new Font("Verdana",Font.PLAIN, 11));
            beloeb.setOpaque(true);
            return beloeb;
        }

    I'm sorry to say this is a terrible example of a renderer. The point of using a renderer is to reuse the same object over and over. You don't keep creating Objects every time a cell is renderered. In your example your are creating:
    a) JFormattedTextField
    b) NumberFormatter
    c) DefaultFormatterFactory
    d) Font.
    So you start by extending the DefaultTableCellRenderer. A JLabel is used to display the text. There is no need to use a JFormattedTextField. All you want to do is format the data. So in your constructor for the class you would create a NumberFormatter that can be reused to format your data. Then your code in the renderer would look something like:
    if (value instanceof Double)
        Double val = (Double)value;
        setText( formatter.format(val) );
        if (negative)
          setForeground(Color.RED)
        else
            setForeground(table.getForeground());
    }Here is a really simple [url http://forum.java.sun.com/thread.jsp?forum=57&thread=419688]example to get you started

  • Strange Problem about KeyListener, and FocusListener

    Hi,Please help me with this problem.
    I create a JTable and setCellEditor by using my customerized TextField
    The problem is: when I edit JTable Cell, the value can not be changed and I can not get Key Event and Focus Event.
    here is my source:
    //create normal JTable instance,and then initlize it
    private void initTable(Vector folders)
    TableColumn tempcol = getColumnModel().getColumn(0);
    tempcol.setCellEditor(new DefaultCellEditor(new MyTextField()));
    for(int i=0;i<folders.size();i++)
    mddDataSource ds=(mddDataSource) folders.get(i);
    String name = ds.getDataSourceName();
    layers.add(name);
    for(int i=0;i<layers.size();i++){
    Vector temp = new Vector();
    temp.add(layers.get(i));
    temp.add(layers.get(i));
    dtm.addRow(temp);
    // My Text Field cell
    class MyTextField extends JTextField implements FocusListener, KeyListener
    MyTextField()
    setOpaque (false);
    addKeyListener(this);
    addFocusListener(this);
    MyTextField(String text)
    setOpaque (false);
    addKeyListener(this);
    addFocusListener(this);
    public void focusGained(FocusEvent e) {
    System.out.println("get Focus");
    public void focusLost(FocusEvent e) {
    instance.setValue(getText());
    public void keyTyped(KeyEvent e){
    instance.setValue(getText());
    public void keyPressed(KeyEvent e){
    System.out.println("get Key ");
    public void keyReleased(KeyEvent e){
    instance.setValue(getText());
    If there are some good sample, please tell me the link or give me some suggestion.
    Thanks in advanced

    Thanks for your help.
    The problem still exist. It does not commit the value that I input.
    Maybe I should say it clearly.
    I have create JPanel include three JPanel:
    Left Panel and right upper-panel and right borrom panel.
    The JTable instance is on right-upper Panel.
    If I edit one of row at JTable and then click JTable other row,the value can be commited. if I edit one of row and then push one Button on
    the right-bottom button to see the editting cell value.It does not commit value.
    when I use debug style, and set breakpoint the
    foucsGained or KeyTyped,
    It never stopes at there,So I assume that the Editing cell never get focus.
    Is there a bug at Java if we move focus on other Panel, that JTable can not detect the Focus lost or focus gained event?
    Thanks

  • JSpinner and FocusListener

    The method addFocusListener of JSpinner doesn't work. Is it a bug?

    No it's not a bug. You might need to try harder to extract from the spinner something that can accept focus:
    import java.awt.event.FocusEvent;
    import java.awt.event.FocusListener;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JSpinner;
    import javax.swing.JTextField;
    import javax.swing.SpinnerNumberModel;
    public class JSpinFocusListener
      private JPanel mainPanel = new JPanel();
      private JSpinner spinner = new JSpinner(new SpinnerNumberModel(0, -10, 10, 1));
      private JTextField textField = new JTextField(10);
      public JSpinFocusListener()
        mainPanel.add(spinner);
        mainPanel.add(textField);
        // this doesn't work
        spinner.addFocusListener(new MyFocusListener("spinner"));
        // and this doesn't work
        spinner.getEditor().addFocusListener(new MyFocusListener("spinner's editor"));
        // but this one, works
        ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField()
            .addFocusListener(new MyFocusListener("spinner's editor's textfield"));
      public JPanel getMainPanel()
        return mainPanel;
      private class MyFocusListener implements FocusListener
        private String name;
        public MyFocusListener(String name)
          this.name = name;
        public void focusGained(FocusEvent e)
          System.out.println("Focus gained on " + name);
        public void focusLost(FocusEvent e)
          System.out.println("Focus lost from " + name);
      private static void createAndShowUI()
        JFrame frame = new JFrame("JSpinFocusListener");
        frame.getContentPane().add(new JSpinFocusListener().getMainPanel());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      public static void main(String[] args)
        java.awt.EventQueue.invokeLater(new Runnable()
          public void run()
            createAndShowUI();
    }

  • Problems with JDesktopPane and JInternalFrame

    hello
    merry christmas .
    I have some strange problem with JDesktopPane .
    I have a frame with an splitpane and in right side of splitpane i have a JDesktopPane .
    I can easily add InternalFrames to this JDesktopPane but when there is two or more InternalFrame and when I have at least 2 internal frame(they are not minimized or in full screen mode or cover completely each other , just when overlap each other) my cpu usage go to 100% and as soon as i minimize one of them or go to full screen mode or drag out one of them problem resolves .
    I have not any extra code that cause this problem(i just overwrite the paint method in internal frames ) .
    Can you help me ?
    Thanks for your time

    Did you override paint() or paintComponent()? Generally you should override paintComponent() for Swing components.
    Regards,
    Tim

  • Shortcut in internalframe

    im making shortcut (jmenuBar method setAcceleratorKeyStroke.getKeyStroke(KeyEvent.VK_K,Event.CTRL_MASK)) )in internalframe
    and it notwork exactly how i want
    if i click to panel, or jmenuBar(they are on this internalframe )
    it not work
    whatis problem with this internalframe ?? on JFrame everything works ok but not hear

    Post a small demo program code that can reproduce your problem.

  • Mark(highlight, bold, and so on) text in GWT (for help)

    I want to display a paragraph text in GWT, in some component(TextArea, or RichTextArea...), and then double-click the words in the text to select them.
    Now I want to highlight the words, can GWT support that effects I need?
    I have tried to use TextArea to display the plain text, add clickListener and focusListener to it. however, I am confused because I don't know how to mark the selected words with highlighting.
    Please tell me how to do that, I will never thank you enough for your help.
    showhappy
    Edited by: showhappy on Jul 24, 2008 11:57 PM
    Edited by: showhappy on Jul 24, 2008 11:58 PM

    I have tried to use TextArea to display the plain text, add clickListener and focusListener to it. however, I am confused because I don't know how to mark the selected words with highlighting.HTML is another widget you can use to display text.
    Marking the selected text is the first problem. AFAIK only TextBoxBase (including TextArea) has a setSelectionRange(int,int) method.
    Figuring out what the selected range should be is the next problem. And I wouldn't have a clue ;( You could use onBrowserEvent() rather than add a click listener. Then you be sent an Event from which you can determine the (x,y) coordinates with respect to the browser's client window. It's up to you to figure out if you are dealing with a double click. The TextBox client coordinates are available from the UIObject methods getAbsoluteTop/Left() but from what I can tell there is no way to determine where (in terms of characters) the click occured.
    Perhaps this is just not the sort of thing you should be doing. For instance in the browsers I looked at - FF, Opera and Konqueror - double clicking in a TextBox or an HTML caused the word clicked on to be selected. But this was an action taken by the browser, not the javascript. It happens on any web page and users expect this behaviour (if they use those browsers) so a case could be made for not messing with what happens when they double click.
    It might be enough for your click listener (or a ChangeListener?) to detect whether both (1) there is some selected text as revealed by getSelectedText() and (2) the selected text is not the same as last time there was a click. Based on these two things you could detect(*) and respond to new selections. This isn't quite what you asked but it might do.
    (* Provided the user is navigating with a mouse, or something that "clicks". Accessibility might be a concern.)
    I'm no expert, so maybe others can help you more. But I wonder if they will do so in this forum whose focus is Java programming, not GWT. If this were a JTextArea, you would be directed to the Swing forum. As it is I don't know where the best place would be. (Post back if you find somewhere good.) A couple of comments here recently suggest that the Google Groups gwt group isn't very active: but perhaps it will only become so if people post their questions there.
    Good luck. (You'll need it with fscking javascript, even if the source language is Java ...;)

  • My graph is out of the frame. InternalFrame

    Hi there.
    I have a InternalFrame and i set the Layout to BoaderLayout, and i set the graph to "Center", and the graph is much too big. how can i set the graph to fit in the internalFrame?? even when i reszie the internalFrame??
    thanks in advance.

    First thing to try is to reset your device. Press and hold the Home and Sleep buttons simultaneously ignoring the red slider should one appear until the Apple logo appears. Let go of the buttons and let the device restart. See if that fixes your problem.

  • The problem of the Canvas and JInternalFrame

    I have some problem with the Canvas and JInternalFrame, my application contains serval internalframes and each has one canvas, but i found that canvas is at the top z-order of the window. so it result in that the canvas is at the same z-level, which confuse very much.
    who can help me with this problem, thanks.

    I think the problem stems from mixing AWT and Swing components (non-lightweight and lightweight)
    if the reason you are using a canvas is for the paint method; do away with them and just use a JPanel (which you can use the paint method within)
    hope this helps?!
    Simon

  • Repaint Problem in JInternalFrame!!!! help plz.

    hi,
    I have a question I have an application that has internal frames, Basically it is a MDI Application. I am using JDK 1.2.2 and windows 2000. The following example shows that when I drag my JInternalFrames only the border is shown and the contents are not shown as being dragged that's fine, but the application I am running have lot of components in my JInternalFrames. And when I drag the JInternalFrame my contents are not being dragged and that's what I want but when I let go the internalFrame it takes time to repaint all the components in the internalFrame. Is there any way I can make the repaint goes faster after I am done dragging the internalFrame. It takes lot of time to bring up the internalframe and it's components at a new location after dragging. Is there a way to speed up the repainting. The following example just shows how the outline border is shown when you drag the internalFrame. As there are not enough components in the internal frame so shows up quickly. But when there are lots of components specially gif images inside the internalframe it takes time.
    /*************** MDITest ************/
    import javax.swing.*;
    * An application that displays a frame that
    * contains internal frames in an MDI type
    * interface.
    * @author Mike Foley
    public class MDITest extends Object {
    * Application entry point.
    * Create the frame, and display it.
    * @param args Command line parameter. Not used.
    public static void main( String args[] ) {
    try {
    UIManager.setLookAndFeel(
    "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
    } catch( Exception ex ) {
    System.err.println( "Exception: " +
    ex.getLocalizedMessage() );
    JFrame frame = new MDIFrame( "MDI Test" );
    frame.pack();
    frame.setVisible( true );
    } // main
    } // MDITest
    /*********** MDIFrame.java ************/
    import java.awt.*;
    import java.awt.event.*;
    import java.io.Serializable;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    * A top-level frame. The frame configures itself
    * with a JDesktopPane in its content pane.
    * @author Mike Foley
    public class MDIFrame extends JFrame implements Serializable {
    * The desktop pane in our content pane.
    private JDesktopPane desktopPane;
    * MDIFrame, null constructor.
    public MDIFrame() {
    this( null );
    * MDIFrame, constructor.
    * @param title The title for the frame.
    public MDIFrame( String title ) {
    super( title );
    * Customize the frame for our application.
    protected void frameInit() {
    // Let the super create the panes.
    super.frameInit();
    JMenuBar menuBar = createMenu();
    setJMenuBar( menuBar );
    JToolBar toolBar = createToolBar();
    Container content = getContentPane();
    content.add( toolBar, BorderLayout.NORTH );
    desktopPane = new JDesktopPane();
    desktopPane.putClientProperty("JDesktopPane.dragMode", "outline");
    desktopPane.setPreferredSize( new Dimension( 400, 300 ) );
    content.add( desktopPane, BorderLayout.CENTER );
    } // frameInit
    * Create the menu for the frame.
    * <p>
    * @return The menu for the frame.
    protected JMenuBar createMenu() {
    JMenuBar menuBar = new JMenuBar();
    JMenu file = new JMenu( "File" );
    file.setMnemonic( KeyEvent.VK_F );
    JMenuItem item;
    file.add( new NewInternalFrameAction() );
    // file.add( new ExitAction() );
    menuBar.add( file );
    return( menuBar );
    } // createMenuBar
    * Create the toolbar for this frame.
    * <p>
    * @return The newly created toolbar.
    protected JToolBar createToolBar() {
    final JToolBar toolBar = new JToolBar();
    toolBar.setFloatable( false );
    toolBar.add( new NewInternalFrameAction() );
    // toolBar.add( new ExitAction() );
    return( toolBar );
    * Create an internal frame.
    * A JLabel is added to its content pane for an example
    * of content in the internal frame. However, any
    * JComponent may be used for content.
    * <p>
    * @return The newly created internal frame.
    public JInternalFrame createInternalFrame() {
    JInternalFrame internalFrame =
    new JInternalFrame( "Internal JLabel" );
    internalFrame.getContentPane().add(
    new JLabel( "Internal Frame Content" ) );
    internalFrame.setResizable( true );
    internalFrame.setClosable( true );
    internalFrame.setIconifiable( true );
    internalFrame.setMaximizable( true );
    internalFrame.pack();
    return( internalFrame );
    * An Action that creates a new internal frame and
    * adds it to this frame's desktop pane.
    public class NewInternalFrameAction extends AbstractAction {
    * NewInternalFrameAction, constructor.
    * Set the name and icon for this action.
    public NewInternalFrameAction() {
    super( "New", new ImageIcon( "new.gif" ) );
    * Perform the action, create an internal frame and
    * add it to the desktop pane.
    * <p>
    * @param e The event causing us to be called.
    public void actionPerformed( ActionEvent e ) {
    JInternalFrame internalFrame = createInternalFrame();
    desktopPane.add( internalFrame,
    JLayeredPane.DEFAULT_LAYER );
    } // NewInternalFrameAction
    } // MDIFrame
    I'll really appreciate for any help.
    Thank you

    Hi
    if you fill the ranges
    r_rundate-sign = 'I'.
    r_rundate-option = 'EQ'.
    r_rundate-low = '20080613'.
    r_rundate-high = '20080613'.
    APPEND r_rundate.
    EQ = 'equal', the select check the record with data EQ r_rundate-low.
    change EQ with BT  
    BT = between
    r_rundate-sign = 'I'.
    r_rundate-option = 'BT'.
    r_rundate-low = '20080613'.
    r_rundate-high = '20080613'.
    APPEND r_rundate.
    reward if useful, bye

  • Jinternalframe won't hide more than once.

    hiya,
    i have a jinternalframe and when i click the close button it hides, but if i show it again and then try to click the close button it doesn't hide. the following code demonstrates the problem - click open then the x to close the internalframe then open again and try to hide the frame. nb i am using jdk1.2.2, i'm not sure if it happens in jdk1.3, but i could really do with a workaround for this...anyone got one?
    thanks!
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.JDesktopPane;
    public class Test extends Frame implements ActionListener {
        JButton openButton;
        JLayeredPane desktop;
        JInternalFrame internalFrame;
        public Test() {
            super("Internal Frame Demo");
            setSize(500,400);
            this.addWindowListener(new WindowAdapter() {
                                       public void windowClosing(WindowEvent evt) {
                                           Window win = evt.getWindow();
                                           win.setVisible(false);
                                           win.dispose();
                                           System.exit(0);
            openButton = new JButton("Open");
            Panel p = new Panel();
            p.add(openButton);
            add(p, BorderLayout.SOUTH);
            openButton.addActionListener(this);
            // Set up the layered pane
            desktop = new JDesktopPane();
            desktop.setOpaque(true);
            add(desktop, BorderLayout.CENTER);
        public void actionPerformed(ActionEvent e) {
            if ((internalFrame == null)) {
                System.out.println("making new frame");
                internalFrame = new JInternalFrame("Internal Frame", true, true, true, true);
                internalFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
                internalFrame.setBounds(50, 50, 200, 100);
            boolean there = false;
            for (int i = 0; i < desktop.getComponentCount(); i++) {
                if (desktop.getComponent(i).equals(internalFrame))
                    System.out.println("already there.");
                    there = true;
            if (!there) desktop.add(internalFrame, new Integer(1));   
            internalFrame.show();
        public static void main(String args[]) {
            Test sif = new Test();
            sif.setVisible(true);

    By Default with JBuilder u have this internalframe and
    JDeskTopPane!!!
    it works just fine (closing and opening again)::::
    Why don't u work with independent classes like:
    JDesktopPane(1), several (JInternalFrame) ???
    // example JDesktopPane ::
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Desktop extends JFrame {
    BorderLayout borderLayout1 = new BorderLayout();
    private JDesktopPane desktopPane = new JDesktopPane();
    JMenuBar menuBar1 = new JMenuBar();
    JMenu menuFile = new JMenu();
    JMenuItem menuFileNewFrame = new JMenuItem();
    public Desktop() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
    jbInit();
    catch (Exception e) {
    e.printStackTrace();
    public void jbInit() throws Exception {
    this.getContentPane().setLayout(borderLayout1);
    this.setContentPane(desktopPane);
    this.setSize(new Dimension(600, 400));
    menuFile.setText("File");
    menuFileNewFrame.setText("New Frame");
    menuFileNewFrame.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    fileNewFrame_actionPerformed(e);
    menuFile.add(menuFileNewFrame);
    menuBar1.add(menuFile);
    this.setJMenuBar(menuBar1);
    static public void main(String[] args) {
    try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    catch(Exception e) {
    Desktop desktop = new Desktop();
    desktop.setVisible(true);
    void fileNewFrame_actionPerformed(ActionEvent e) {
    InternalFrame frame = new InternalFrame();
    frame.setBounds(0, 0, 450, 300);
    desktopPane.add(frame, new Integer(1));
    protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if(e.getID() == WindowEvent.WINDOW_CLOSING) {
    System.exit(0);
    // example JInternalFrame ::
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class InternalFrame extends JInternalFrame {
    BorderLayout borderLayout1 = new BorderLayout();
    public InternalFrame() {
    try {
    jbInit();
    catch (Exception e) {
    e.printStackTrace();
    public void jbInit() throws Exception {
    this.setClosable(true);
    this.setIconifiable(true);
    this.setMaximizable(true);
    this.setResizable(true);
    this.getContentPane().setLayout(borderLayout1);
    }

  • Showing images in a GUI

    Hi there i was wondering if i could ask for some assistance.
    I have written a system that will read in a file and modify its pixel content and then write the new image to file. i now want to develop a gui that will allow me to show the initial image on one panel (or internalFrame) and have another to show the new image, however i am at a complete loss as how to do this. can anyone recommend really good tutorials or code sample for me to study?
    any information is greatly appreciated.

    What is the graphic format of your image file ?
    If compatible, you can directly use it in a JLabel like below:
    JLabel imgLabel = new JLabel(new ImageIcon("yourFile.gif")); // .gif for examplethen, you just put the label into any Container.

  • Help needed in understanding GridBagLayout situation

    I have a JPanel with a JInternalFrame and a few JPanels inside of it. The JPanel is using GridBagLayout.
    When a user moves the JInternalFrame inside of the panel what is happening exactly? How is it moving the frame with relation to the Layout? It doesn't appear to be bound by the Layout. When the user drags the frame to a new location what methods are being invoked?

    Having looked at the JXMapViewer which extedns XJPanel and XJPanel extends JPanel.
    so if you want to get notified you need to add ComponentListener to the instance of JXMapViewer to get notificed when the following happens
    The below is a copy from java tutorial for internalframe and I have added the MyComponentListener just to give you some ideas.
    Hope this could help
    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.*;
    * 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();
            MyComponentListener listener = new MyComponentListener();
            frame.addComponentListener(listener);
            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();
    private class MyComponentListener implements ComponentListener {
              * Invoked when the component's size changes.
             public void componentResized(ComponentEvent e) {
                  System.out.println("comp resized");
              * Invoked when the component's position changes.
             public void componentMoved(ComponentEvent e) {
                  System.out.println("comp moved");
              * Invoked when the component has been made visible.
             public void componentShown(ComponentEvent e) {
                  System.out.println("comp shown");
              * Invoked when the component has been made invisible.
             public void componentHidden(ComponentEvent e) {
                  System.out.println("comp hidden");
         } // listener class
    /* Used by InternalFrameDemo.java. */
    private class MyInternalFrame extends JInternalFrame {
         int openFrameCount = 0;
         final int xOffset = 30, yOffset = 30;
        public MyInternalFrame() {
            super("Document #",
                  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);
            //Set the window's location.
            setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
    }Regards,
    Alan Mehio
    London, UK

  • Problem in Disabled the Menus

    hi everyone,
    Hello am developing a application in java. I used InternalFrame and JDesktop.. My problem is after the login i want to disabled the menu in the Menubar when the user login sucessfully it will be enabled and ready to click. But am having a problem because my code in login is separated into the MainFrame.. i got to java file 1. MainFrame_PCM.java and MyLoginInternalFrame.java. So when the MainFrame_PCM was run it will call MyLoginInternalFrame as my login in window what i want is by default the MenuBar in MainFrame_PCM was set disabled and after login successfully i will set them enabled .Hope you understand my problem .Any help will do ..
    Thank you very much in advance
    Armando Dizon

    Hi Pravinth,
    Thank you very very much in reply in my email.Below is my code of the MainFrame and the LoginFrame as i mention in my previous post. The scencario in the thread that similar in my problem is you have to go to Main menu and click login and login form or frame will pop up in my case automatic popup and what i want sir is when the popup frame will appear and successfully login the Menu will be setEnabled. Thank you i really apprecaite your help
    /*File name : MainFrame_PCM.java*/
    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.*;
    * MainFrame_PCM.java is a 1.4 application that requires:
    * MyInternalFrame.java
    public class MainFrame_PCM extends JFrame implements ActionListener
    JDesktopPane desktop;
    public MainFrame_PCM()
    super("Peso Collection Module");
    //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
    createLoginFrame(); //create first "window"
    setContentPane(desktop);
    setJMenuBar(createMenuBar());
    //Make dragging a little faster but perhaps uglier.
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    /* This portion creates the Menu Tool Bar.
    // And creates the Menu Toor Bar sub menus.
    // Ining parti na ning code a ini gawa yang
    //menu Bar and Sube menus pra keng Main Menu
    protected JMenuBar createMenuBar()
    JMenuBar menuBar = new JMenuBar();
    //Set up Main Menus
    JMenu menu = new JMenu("Main Menu");
    menu.setMnemonic(KeyEvent.VK_D);
    menuBar.add(menu);
    JMenu menu2 = new JMenu("Maintenance");
    menu2.setMnemonic(KeyEvent.VK_M);
    menuBar.add(menu2);
    ///////////////////// SUB MENUS CODE HERE ///////////////////
    //a submenu
              menu2.addSeparator();
              JMenu submenu = new JMenu("Manage Users");
              submenu.setMnemonic(KeyEvent.VK_S);
              JMenuItem menuItem8 = new JMenuItem("Add New User");
              menuItem8.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_A, ActionEvent.ALT_MASK));
              menuItem8.setActionCommand("adduser");
              menuItem8.addActionListener(this);
              submenu.add(menuItem8);
              JMenuItem menuItem9 = new JMenuItem("Edit User Profile");
              menuItem9.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_E, ActionEvent.ALT_MASK));
              menuItem9.setActionCommand("editusers");
              menuItem9.addActionListener(this);
              submenu.add(menuItem9);
              menu2.add(submenu);
              JMenuItem menuItem10 = new JMenuItem("Delete User");
              menuItem10.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_D, ActionEvent.ALT_MASK));
              menuItem10.setActionCommand("deleteusers");
              menuItem10.addActionListener(this);
              submenu.add(menuItem10);
              menu2.add(submenu);
              //Set up the Maintenance Menu item.
    JMenuItem menuItemMtc = new JMenuItem(" Program Access");
    menuItemMtc.setMnemonic(KeyEvent.VK_U);
    // menuItemMtc.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_L, ActionEvent.ALT_MASK));     
    menuItemMtc.setActionCommand("manage_users");
    menuItemMtc.addActionListener(this);
    menu2.add(menuItemMtc);
              /*--------End of Maintenance Menu item--------*/
    //Set up the Main menu item.
    JMenuItem menuItem = new JMenuItem("Login");
    menuItem.setMnemonic(KeyEvent.VK_L);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(
    KeyEvent.VK_L, ActionEvent.ALT_MASK));     
    menuItem.setActionCommand("login");
    menuItem.addActionListener(this);
    menu.add(menuItem);
              JMenuItem menuItem2 = new JMenuItem("User Maintenance");
    menuItem2.setMnemonic(KeyEvent.VK_N);
    menuItem2.setAccelerator(KeyStroke.getKeyStroke(
    KeyEvent.VK_N, ActionEvent.ALT_MASK));     
    menuItem2.setActionCommand("user");
    menuItem2.addActionListener(this);
    menu.add(menuItem2);
              //Set up the QUIT 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);
    /*--------End of Main Menu item--------*/
    return menuBar;
    //////////////////// END OF SUB MENUS HERE ////////////////////
    //React to Sub menu selections. keni la mayayaus deng forms potng me click!
    public void actionPerformed(ActionEvent e)
    if ("login".equals(e.getActionCommand())) //new login fram
    createLoginFrame();
                   else if ("user".equals(e.getActionCommand())) //new temporary ya ini
                   createFrame();
                   else if ("adduser".equals(e.getActionCommand())) //new user frame
                   createManageUserFrame();//call the Manage User Form Functions
                   else if ("editusers".equals(e.getActionCommand())) //new user frame
                   createEditUserFrame();//call the Edit User Form Functions
                   else if ("deleteusers".equals(e.getActionCommand())) //new user frame
                   createDeleteUserFrame();//call the Edit User Form Functions
              else //quit
    quit();
         /*-------------- End Of Sub Menus Reactions ------------*/     
         //Create a new internal frame for User Login
              protected void createLoginFrame()
                   MyLoginInternalFrame frame = new MyLoginInternalFrame();
                   frame.setVisible(true); //necessary as of 1.3
                   desktop.add(frame);
                   try
                        frame.setSelected(true);
                   } catch (java.beans.PropertyVetoException e) {}
              //Create a new internal frame for User Maintenance TEMPORARY YA INI BOI
              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) {}
              // Create a new internal fram for Manage Users
              protected void createManageUserFrame()
                   ManageUserForm frame = new ManageUserForm();
                   frame.setVisible(true); //necessary as of 1.3
                   desktop.add(frame);
              try
                        frame.setSelected(true);
                   } catch (java.beans.PropertyVetoException e) {}
              // Create a new internal fram for Edit Users
              protected void createEditUserFrame()
                   createEditUserForm frame = new createEditUserForm();
                   frame.setVisible(true); //necessary as of 1.3
                   desktop.add(frame);
              try
                        frame.setSelected(true);
                   } catch (java.beans.PropertyVetoException e) {}
              // Create a new internal fram for Edit Users
              protected void createDeleteUserFrame()
                   createDeleteUserForm frame = new createDeleteUserForm();
                   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.
    MainFrame_PCM frame = new MainFrame_PCM();
    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();
    /*File name : MyLoginInternalFrame.java*/
    import javax.swing.JInternalFrame;
    import javax.swing.JLabel;
    import javax.swing.JButton;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    public class MyLoginInternalFrame extends JInternalFrame implements ActionListener
         static final int xOffset = 320, yOffset = 200;
         JPasswordField pass_word;
         JTextField user_name;
         JLabel lbl;
         JButton btnclear, btnexit,btnsearch;
         String url;
         Connection connect;
    public MyLoginInternalFrame()
         super("User Login ");
                        //Database Connectivity
                        try
                        url = "jdbc:odbc:Plogbook";
                        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                        connect = DriverManager.getConnection(url);
                             catch(ClassNotFoundException cnfex)
                             cnfex.printStackTrace();
                             System.err.println("Failed to load JDBC/ODBC driver");
                             System.exit(1);     
                             catch (SQLException sqlex)
                             sqlex.printStackTrace();     
                             catch (Exception ex)
                             ex.printStackTrace();     
                   //Fields to be Set Up
                   Container c = getContentPane();
                   GridLayout ly = new GridLayout(0,3);
                   c.setLayout(ly);
                   //Blank Labels
                   lbl = new JLabel(" ");
                   c.add(lbl);
                   lbl = new JLabel(" ");
                   c.add(lbl);
                   lbl = new JLabel(" ");
                   c.add(lbl);
                   lbl = new JLabel(" Username:");
                   c.add(lbl);
                   user_name = new JTextField(20);
                   user_name.setToolTipText("Enter Your User Name");
                   c.add(user_name);
                   lbl = new JLabel(" ");
                   c.add(lbl);
                   lbl = new JLabel(" Password:");
                   c.add(lbl);
                   pass_word = new JPasswordField(200);
                   pass_word.setToolTipText("Enter Your Password");
                   c.add(pass_word);
                   lbl = new JLabel(" ");
                   c.add(lbl);
                   lbl = new JLabel(" ");
                   c.add(lbl);
                   lbl = new JLabel(" ");
                   c.add(lbl);
                   lbl = new JLabel(" ");
                   c.add(lbl);
                   btnsearch = new JButton("Login");
                   btnsearch.addActionListener(this);
                   c.add(btnsearch);
                   //btnclear = new JButton("Clear");
                   //btnclear.addActionListener(this);
                   //c.add(btnclear);
                   btnexit = new JButton("Cancel");
                   btnexit.addActionListener(this);
                   c.add(btnexit);
                   //Blank Labels
                   lbl = new JLabel(" ");
                   c.add(lbl);
                   lbl = new JLabel(" ");
                   c.add(lbl);
                   lbl = new JLabel(" ");
                   c.add(lbl);
                   setSize(300,150);
                   setLocation(xOffset, yOffset);
                   //Quit the application.
                   protected void quit()
                   System.exit(0);
                   public void actionPerformed(ActionEvent e)
                   // Clear the fields
                        if(e.getSource() == btnclear)
                        user_name.setText("");
                        pass_word.setText("");
                   // Exit the program
                        if(e.getSource() == btnexit)
                        //setVisible(false);
                        quit();
                             // Search the file
                                  if(e.getSource()==btnsearch)
                                            try
                                                 Statement statement=connect.createStatement();
                                                 String sqlQuery ="SELECT * FROM a_user WHERE user_id = '"+ user_name.getText() + "' AND password = '"+ pass_word.getText() + "'";
                                                 ResultSet rs = statement.executeQuery(sqlQuery);
                                                 if(rs.next())
                                                      setVisible(false);
                                                      JOptionPane.showMessageDialog(null,"ACCESS GRANTED");     
                                                      else
                                                           JOptionPane.showMessageDialog(null,"ACCESS DENIED");
                                                           user_name.setText("");
                                                           pass_word.setText("");
                                                 catch (SQLException sqlex)
                                                      sqlex.printStackTrace();          
                                                      JOptionPane.showMessageDialog(null, sqlex.toString());     
                   public static void main(String arg[])
                             MyLoginInternalFrame frm = new MyLoginInternalFrame();
                             frm.show();
    }

  • Changing JButtons

    I have a simple application which needs small images to change dependant on user input.
    At the minute I have used an extended JButton (extended to implement mouseListener and focusListener) but I need the image I have on them to change if someone right clicks it. My attempts to get the image to change have failed miserably ;-)
    Is it possible to alter components once they have been added to a pane?
    If not, what would be the best way to achieve the desired result?
    Cheers

    Read up on some of these methods in AbstractButton: setIcon(), setSelectedIcon(), setRolloverIcon()...

Maybe you are looking for

  • ALV functionality in Visual Composer 7.0

    Hi colleagues, I have easy question, is anybody know have Visual Composer 7.0 ALV functionality or no? If it have, is it concerning to BI models only, or it can be concerning to any models in Visual Composer 7.0? Thanks in advance. Regards Dmitriy

  • Ibook g4 cant turn on with charger, but works fine with battery

    i have a ibook g4 cant turn on with charger. using battery, ibook works fine-----so not the battery problem charger works fine on other ibook-----so not the charger problem the DC-in board works fine on other ibook-----so not the DC-in problem reset

  • Content Server 5 error

    Hi, can someone help me with this error message below. It is appearing in our pcserr.log. We are using CS 5.02 Thanks very much. Lars java.lang.StringIndexOutOfBoundsException: String index out of range: -37776 at java.lang.String.substring(String.ja

  • ITunes says i have all purchases but i dont

    I recently tryed getting the music i got from itunes onto my computer with the store. It says i already have all purchases but they arent on my library or computer at all. How do i get those songs back without paying for them again?

  • Help with proxy settin

    when i try to sync my songs with windows media player it says error: WMP can't access this file the file might be in use, you might not have access to this file or your proxy settings might not be correct. and the same for when I used zenvision m sof