Rootpanes and ActionListeners

Hi,
I have an Actionlistener on the rootpane of a JFrame to catch when the user hits 'ESC' (using 'registerKeyboardAction'). This works ok no matter what Swing object has the focus, except when a JTable or JTree has the focus. Is this a bug and is there a work around?

Figured it out.
Use the following to deactivate the ESC key for JTables and JTrees
jTable1.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).getParent().remove(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false));
jTree1.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).getParent().remove(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false));

Similar Messages

  • Actions and ActionListeners as parameters

    Hi everybody,
    I want to overload a method so it can take either 2 Actions, 2 ActionListeners, or one of each. The issue with this is that I'd have to make 4 overloaded signatures and almost identical methods, like this:
    method( action, action )
    method( action, listener )
    method( listener, action )
    method( listener, listener )It seems like doing it this way would result in a lot of extra code, and hence become a real pain in the neck. So, I was curious, has anyone else either tried to do this before, or do you have any ideas as to how I might be able to do this more efficiently? When I looked at the API it didn't look like Actions and ActionListeners share a root class I can use.
    Thanks,
    Jezzica85

    jezzica85 wrote:
    Hi everybody,
    I want to overload a method so it can take either 2 Actions, 2 ActionListeners, or one of each. The issue with this is that I'd have to make 4 overloaded signatures and almost identical methods, like this:
    method( action, action )
    method( action, listener )
    method( listener, action )
    method( listener, listener )
    Well, if you want to support that then you are just going to have to do suffer through it, the only shortcut I can recommend is that your method(action, listener) and method(listener, action) are the same so you only have to implement 1 and just use the other as a entry point to call the one you wish to contain the code.

  • JSF Actions and ActionListeners with Tiles and forms

    I�m having a problem trying to use the Tiles functionality in Struts 1.1 with JSF and was wondering if anyone could help me.
    I have defined a very simple header, menu, content Tile that doesn�t involve nesting of tiles (ExampleTile_content1Level.jsp).
    I have 3 JSP pages, the first testHarness.jsp is NOT built using Tiles and is just used to load some test data into a session scoped bean using an actionListener and then forward to a Tile generated page (ExampleTile3.jsp) using a hard-coded action �applicationSummary� when a commandLink is pressed. This works fine for both the action and actionListener.
    ExampleTile3.jsp contains another commandLink that is meant to forward to another tile ExampleTile2.jsp. This also works until I try to add the <h:form> � </h:form> tag around the outside of the <h:panelGrid> tags in ExampleContent1.jsp when the action and actionListener then fail to fire and I get an �Error on Page� message in Explorer the detail of which says �Error �com_sun_rave_web_ui_appbase_renderer_CommandLinkRendererer� is null or not an object�.
    However I need a form so that I can bind UI controls to data from the bean stored in the session scope. This is only a problem when I use Tiles to define the pages. Does anyone know what I am doing wrong?
    Any help would be much appreciated.
    Tiles.xml
       <definition name="example3" path="/pages/exampleTile_content1Level.jsp" >
              <put name="headerClass" value="someStyle"/>
              <put name="menuClass" value="someStyle"/>
              <put name="contentClass" value="someStyle"/>
              <put name="header-title" value="/pages/exampleHeader.jsp" />
              <put name="menu" value="/pages/exampleMenu.jsp" />
              <put name="content" value="/pages/exampleContent1.jsp" />
       </definition>
       <definition name="example2" path="/pages/exampleTile_content1Level.jsp" >
              <put name="headerClass" value="someStyle"/>
              <put name="menuClass" value="someStyle"/>
              <put name="contentClass" value="someStyle"/>
              <put name="header" value="/pages/exampleHeader.jsp" />
              <put name="menu" value="/pages/exampleHeader.jsp" />
              <put name="content" value="/pages/exampleContent2.jsp" />
       </definition>ExampleTile3.jsp
    <f:view>
         <h:form>
              <tiles:insert definition="example3" flush="false" />
         </h:form>
    </f:view> ExampleTile2.jsp
    <f:view>
         <h:form>
              <tiles:insert definition="example2" flush="false" />
         </h:form>
    </f:view> Faces-config.xml
    <navigation-rule>
        <from-view-id>/pages/testHarness.jsp</from-view-id>
           <navigation-case>
                <from-outcome>applicationSummary</from-outcome>
                <to-view-id>/pages/exampleTile3.jsp</to-view-id>
              <redirect/>
           </navigation-case>
    </navigation-rule>
    <navigation-rule>
        <from-view-id>/pages/exampleTile3.jsp</from-view-id>
           <navigation-case>
                <from-outcome>nextPage</from-outcome>
                <to-view-id>/pages/exampleTile2.jsp</to-view-id>
                <redirect/>
           </navigation-case>
    </navigation-rule> ExampleTile_content1Level.jsp
    <tiles:importAttribute scope="request"/>
    <h:panelGrid columns="1" >
         <f:subview id="header-title">
              <tiles:insert name="header-title" flush="false" />
         </f:subview>
         <f:subview id="menu">
              <tiles:insert name="menu" flush="false" />
         </f:subview>
         <f:subview id="content">
              <tiles:insert name="content" flush="false" />
         </f:subview>
    </h:panelGrid> ExampleHeader.jsp / ExampleMenu.jsp
    <tiles:importAttribute scope="request"/>
    <h:panelGrid columns="1" columnClasses="someSyle">
         <h:outputFormat value="This is the {0}.">
              <f:param value="Header / Menu as appropriate "/>         
         </h:outputFormat>
    </h:panelGrid> ExampleContent1.jsp
    <tiles:importAttribute scope="request"/>
    <h:form>     <----- Fails with this tag included but works without it.
    <h:panelGrid columns="1" >
              <h:outputFormat value="This is the {0}.">
                   <f:param value="Content on the FIRST page"/>
              </h:outputFormat>
              <h:commandLink action="nextPage" immediate="false">
                   <h:outputText value="Click to go to next page"/>
              </h:commandLink>
    </h:panelGrid>
    </h:form> ExampleContent2.jsp
    <tiles:importAttribute scope="request"/>
    <h:panelGrid columns="1" >
         <h:outputFormat value="This is the {0}.">
              <f:param value="Content on the SECOND page"/>
         </h:outputFormat>
    </h:panelGrid>

    jezzica85 wrote:
    Hi everybody,
    I want to overload a method so it can take either 2 Actions, 2 ActionListeners, or one of each. The issue with this is that I'd have to make 4 overloaded signatures and almost identical methods, like this:
    method( action, action )
    method( action, listener )
    method( listener, action )
    method( listener, listener )
    Well, if you want to support that then you are just going to have to do suffer through it, the only shortcut I can recommend is that your method(action, listener) and method(listener, action) are the same so you only have to implement 1 and just use the other as a entry point to call the one you wish to contain the code.

  • What's the difference between Action Objects and ActionListeners

    Hello,
    in the Introduction to JSF two ways handling action are demonstrated. One way is "Combining Component Data and Action Object" the other way is "Handling Events."
    What's the difference? When do I use this or that way?
    The one thing I understand is when using "Combining Component Data and Action Objects" I use the default ActionListener and I may directly access the input values.
    TIA,
    Juergen

    Hi Juergen,
    The bottomline is 'not much', only in the details to these two approaches differ.
    The ActionListener object will have events broadcast to it for a particular object by the event mechanism in JSF. You can add one to a specific component via the f:action_listener tag. This will have your listener getting events during specific points in the request processing lifecycle (you specify via your return value for getPhaseId).
    The Action class that an actionRef reference refers to an Action that will be invoked during the invoke application phase. (see pg 71).
    I would recommend using actionRefs and Action objects wherever possible and going to ActionListeners only when you need notifications during a specific phase of the request/response cycle.
    Hope this helps,
    -bd-
    http://bill.dudney.net

  • JButton and ActionListeners

    I would like to change the ActionListeners registered to a JButton when the user clicks on a JButton. However there is a problem with this (see below). A typical procedure would go as follows:
    1) User clicks on button
    2) Get the appropriate listener from a list of listeners
    3) Remove the current listener(s) from the button
    4) Add the new listener(s)
    However, for some reason, the instructions of the new listener class are getting called. Is there a way of preventing this and if so, can someone please guide me in the right direction?
    Stephen

    It does not seem to happen like what you have said. Please see the test code below:
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.WindowConstants;
    public class Temp extends JFrame {
         private JButton b = null;
         public Temp() {
              super("Test");
              setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              getContentPane().setLayout(new BorderLayout());
              b = new JButton("Click Me!");
              b.addActionListener(new ActionListener1());
              getContentPane().add(b);
              pack();
              setVisible(true);
         class ActionListener1 implements ActionListener {
              public void actionPerformed(ActionEvent evt) {
                   System.out.println("Action Listener 1");
                   b.removeActionListener(this);
                   b.addActionListener(new ActionListener2());
         class ActionListener2 implements ActionListener {
              public void actionPerformed(ActionEvent evt) {
                   System.out.println("Action Listener 2");
         public static void main(String args []) {
              new Temp();
    }The first time you click the button action listener 1 code gets executed. From the second time onwards the action listener 2 code gets executed.
    Hope this helps
    Sai Pullabhotla

  • Reflection, menus, and ActionListeners

    Hi everybody,
    I was doing some reading in the Java APIs and came across reflection, and it seemed like a good idea for some menus I'm implementing, but I'm not fully sure, so I'd like some advice, please, if anyone would be willing.
    I have a lot of menus on a menu bar, and each menu item on the bar pops up a different kind of window (each window is distinct and has its own constructor; they're all encapsulated objects). My original idea was to add actionListeners to each menu item like so:
    for each item:
    item.addActionListener( new ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    // the constructor for a particular window
    });The issue with that approach, as I've learned, is that this repetitive call, while it works, bloats my classes, makes them almost impossible to read, and involves a lot of cutting and pasting so it's prone to mistakes.
    So...then I stumbled on reflection. From reading the API, it appears (please correct me if I'm wrong) that you can get particular methods and constructors from classes using reflection, and then call them. This would allow me to make two small overloaded methods, to cut down on the amount of code, like so:
    public JMenuItem addConstructorAction( JMenuItem item, Constructor c ) {
    item.addActionListener( new ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    c.newInstance();
    return item;
    public JMenuItem addConstructorAction( JMenuItem item, Method m ) {
    item.addActionListener( new ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    m.invoke( params );
    return item;
    }So, am I right that this is how reflection works, or have I misread something? If anyone could give me advice on how to use this properly or an alternate idea, I'd appreciate it.
    Thanks,
    Jezzica85
    PS -- Sorry about the indenting on the code examples; I don't know why they didn't indent, hopefully they're still readable.
    Edited by: jezzica85 on Jan 14, 2009 7:04 AM

    Well, I didn't think this would turn into a SSCCE situation, but that's OK-- I probably should have assumed that to begin with. Anyway, here's a small program that shows what I'm talking about:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    public class MenuTest {
         public static void main(String[] args) {
              try {
                   JFrame frame = new JFrame();
                   frame.setSize( 300, 300 );
                   frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
                   JMenuBar test = new JMenuBar();
                   JMenu menu = new JMenu( "myTest" );
                   JMenuItem item = new JMenuItem( "TestWindow test" );
                   item.addActionListener( new ActionListener() {
                        public void actionPerformed( ActionEvent ex ) {
                             new TestWindow( "TestWindow" );
                   menu.add( item );
                   JMenuItem item2 = new JMenuItem( "TestWindow2 test" );
                   item2.addActionListener( new ActionListener() {
                        public void actionPerformed( ActionEvent ex ) {
                             new TestWindow2( "TestWindow2" );
                   menu.add( item2 );
                   test.add( menu );
                   frame.setJMenuBar( test );
                   frame.setVisible( true );
              } catch( Exception e ) {
                   e.printStackTrace();
                   System.exit( -1 );
    class TestWindow extends JDialog {
         public TestWindow( String title ) {
              setTitle( title );
              setSize( 300, 300 );
              setDefaultCloseOperation( JDialog.DISPOSE_ON_CLOSE );
              setVisible( true );
    class TestWindow2 extends JDialog {
         public TestWindow2( String title ) {
              setTitle( title );
              add( new JLabel( "blah" ) );
              setSize( 300, 300 );
              setDefaultCloseOperation( JDialog.DISPOSE_ON_CLOSE );
              setVisible( true );
    }Basically, each menu item calls up a different kind of window (these are very simplified obviously). In my real application I have more than 40 different windows (because the application needs to do a lot), so repeating the actionListener code can get tedious. It doesn't look like much here, but 9 lines of code (including whitespace for readability) times at least 40 menu items is more than 350 lines of code for menu items alone. That's what I'm trying to avoid.
    Thanks,
    Jezzica85

  • JMenus and ActionListeners

    I'm making a MineSweeper clone and need some pointers on how to let people start a new game by either going to Game and choosing new or Ctrl_N.
    Here is what I have so far:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    public class Menus extends JMenu
    private static TimerDisplay TD=new TimerDisplay();
    public static JMenuBar menus()
    JMenuBar mb=new JMenuBar();
    JMenu game=new JMenu("Game");
    game.setMnemonic(KeyEvent.VK_G);
    mb.add(game);
    JMenuItem nw=new JMenuItem("New");
    nw.setMnemonic(KeyEvent.VK_N);
    nw.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
    nw.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent event)
    // What could I put here.
    JMenuItem exit=new JMenuItem("Exit");
    exit.setMnemonic(KeyEvent.VK_E);
    exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK));
    exit.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent event)
    System.exit(0);
    game.add(nw);
    game.add(new JSeparator());
    game.add(exit);
    return mb;
    }

    I would probably opt for a different way of thinking about this. First off, I'd get rid of all of the statics there and make Menus a true OOP class. Next, I'd try to have it communicate in an OOP fashion with the class that displays and runs the game itself, here in my example called "MyGame". I'd give MyGame class an exit() method to allow it to decide how to exit, and a reset() method to allow it to decide how it wants to reset for a new game. This way the menus shouldn't have to and doesn't worry about these things. Something like so:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import javax.swing.*;
    public class Menus //extends JMenu
      private JMenuBar menubar = new JMenuBar();
      // a timerdisplay object may not be needed in the menu class
      //private TimerDisplay timerDisplay = new TimerDisplay();
      private MyGame myGame;
      Menus()
      //public void setGameDisplay(MyGame myGame, TimerDisplay timerDisplay)
      public void setGameDisplay(MyGame myGame)
        this.myGame = myGame;
        //this.timerDisplay = timerDisplay; // probably not needed
        initMenus();
      public JMenuBar getMenuBar()
        return menubar;
      public void initMenus()
        JMenu gameMenu = new JMenu("Game");
        gameMenu.setMnemonic(KeyEvent.VK_G);
        menubar.add(gameMenu);
        JMenuItem nw = new JMenuItem("New");
        nw.setMnemonic(KeyEvent.VK_N);
        nw.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
            ActionEvent.CTRL_MASK));
        nw.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent event)
            myGame.reset();
        JMenuItem exit = new JMenuItem("Exit");
        exit.setMnemonic(KeyEvent.VK_E);
        exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4,
            ActionEvent.ALT_MASK));
        exit.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent event)
            //System.exit(0);
            myGame.exit();
        gameMenu.add(nw);
        gameMenu.add(new JSeparator());
        gameMenu.add(exit);
    }Then it could all be tied together with a Controller or Main class that creates the MyGame class, creates the Menus class and adds one to the other.

  • PJC and actionlisteners

    Hi,
    I'm developing a bean, and want to use it as a pjc in a form, using the VBean package of Forms.
    The component extends VBean and implements a DocumentListener.
    I instansiate a JPanel and add the component.
    The set_property methods works fine and the document listener is working.
    The component that I'm using extends JFrame and implements ActionListener, WindowListener, DocumentListener, FocusListener.
    Problem is: The PJC is not listening to /firing various events
    How do I get the PJC to listen to actions like keyboard short-cuts that when running the bean outside forms works as expected. What am I missing ?
    Any thoughts much appreciated
    Thanks

    I havn't implemented the addtional listeners for the class that extends vbean
    This is what I've got so far:
    public class mybean extends VBean implements DocumentListener
    private Component mComp = new JPanel()
    /*** Constructor*/
    public mybean() {
    super();
    eclass = new Eclass(this);
    // this class has all the listeners implemented
    try {
    mComp = (JPanel) eclass.getedComponent();
    } catch (Exception ee) {
    ee.printStackTrace();
    How do I get the listeners in the class I instansiate active in the vbean implementation

  • Executable JARs, JFrames, and ActionListeners

    I'm fairly new to Java, and am currently attempting to create my first JAR executable file. I am using the Eclipse IDE and JDK 5.0. I use Eclipse's export option to create a JAR executable. When the JAR is exectued, it successfully creates and displays the intial JFrame; however, a second JFrame that is created by an ActionListener on a JButton, and is based on input from a JTextArea, is never created when the JButton is clicked on. The second JFrame also accesses txt files based upon the JTextArea input, each of which are contained inside of the JAR file as well. The program compiles and runs successfully when ran as a Java Application or SWT Application in Eclipse, so I am unsure why the export ability is not working.
       public FrameClass1()
          inputTextArea = new JTextArea(29, 95);
          inputTextArea.setFont(new Font("Courier New", 0, 12));
          //Adds the inputTextArea to a JScrollPane, and then adds it to the frame's Center
          buttonPanel = new JPanel();
          submitButton = new JButton("Submit");
          submitButton.addActionListener(new
             ActionListener()
                public void actionPerformed(ActionEvent event)
                   String textInput = inputTextArea.getText();
                   //Output frame creation
                   FrameClass2 outputFrame = new FrameClass2(textInput);
                   outputFrame.setVisible(true);
          buttonPanel.add(submitButton);
          //buttonPanel is added to the frame's south portion
       }Any suggestions as to why the second frame class is not being generated and how to fix it are greatly appreciated. Thanks in advance.

    To capture the error messages, I've used this try-catch statement, though as I posted earlier, I am not familar with JARs. I have identified that my error is a IllegalArguementException, though I cannot find a precise location of where this exception occurs, as the exceptionOutputFrame is never populated with the stack trace. I've tried both e.getMessage() (below) and e.printStackTrace().toString() with both JLabels and JTextAreas, but the JPanel will not populate with data. Could anybody recommend a good method of outputing the stack trace? In addition, could someone explain the use of getResourceAsStream a little more? Should I be using the class ClassLoader's method or the interface ServletContext? I'm a little rough around the edges with the idea of a resource, so does anybody have a good online reference that I could look at?
         try
              // Insert output frame creation here.
              Class2 outputFrame = new Class2(textInput);
              outputFrame.setVisible(true);
         catch(Exception e)
              JFrame exceptionOutputFrame = new JFrame(e.getClass().getName());
              JScrollPane exceptionOutputScrollPane = new JScrollPane();
              JPanel exceptionOutputPanel = new JPanel();
              JTextArea exceptionOutputLabel = new JTextArea(e.getMessage());
              exceptionOutputPanel.add(exceptionOutputLabel);
              exceptionOutputScrollPane.add(exceptionOutputPanel);
              exceptionOutputFrame.add(exceptionOutputScrollPane);
              exceptionOutputFrame.setSize(exceptionOutputLabel.getWidth(), DEFAULT_HEIGHT);
              exceptionOutputFrame.setVisible(true);
         catch(Error e)
              JFrame errorOutputFrame = new JFrame(e.getClass().getName());
              JScrollPane errorOutputScrollPane = new JScrollPane();
              JPanel errorOutputPanel = new JPanel();
              JTextArea errorOutputLabel = new JTextArea(e.getMessage());
              errorOutputPanel.add(errorOutputLabel);
              errorOutputScrollPane.add(errorOutputPanel);
              errorOutputFrame.add(errorOutputScrollPane);
              errorOutputFrame.setSize(errorOutputLabel.getWidth(), DEFAULT_HEIGHT);
              errorOutputFrame.setVisible(true);
         }

  • WindowListeners and actionListeners

    Hey guys, thanks for all your help the other night with my actionListner problem. This time around, it isn't as much a problem of getting the program to work, it's just a matter of how to do things. I have an actionListener created like this:
    button.addActionListener(mainFrame);
    public void actionPerformed (ActionEvent e) {
    How can I create a windowListener in this manner instead of this:
              mainFrame.addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                        System.exit(0);
              } );I hope somebody can help! thanks for your time and input.
    Tom

    You do it exactly the same way, except whatever class is implementing WindowListener will need to add a lot more methods. Extending WindowAdapter allows you to over-ride only the methods you need to, like windowClosing.

  • Creating and moving images

    Hi, I would like to make a game as hobby in Java but have no clue of anything. Can anyone show me how to create and move the images? I don't know how to show an image in window but I do know about JComponents and actionListeners such as mouse and key. Thank you.

    look at the image and applet api and then create an image with the getImage method in the applet api
    once youve created it, paint it in the paint method
    to paint:
    g.drawImage(Image imageName, int xPosition, int yPosition, Component? imageProducer/**u can just use this*/);then youll prolly hav a speed variable.
    just do things like
    xPosition += xSpeed;
    and
    yPosition += ySpeed;
    then the update method to make it not flash... rememb to add Graphics dbg as an instance variable...
    public void update(Graphics g)
              if (dbImage == null)
                  dbImage = createImage (this.getSize().width, this.getSize().height);
                  dbg = dbImage.getGraphics ();
              dbg.setColor (getBackground ());
              dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
              dbg.setColor (getForeground());
              paint (dbg);
              g.drawImage (dbImage, 0, 0, this);
          }

  • Resizing and/or Moving the JFrame on the Screen

    Is there any way to resize a JFrame when the undecorated property is set to true.
    I would like to have a JFrame that is both undecorated and resizable.
    Similarly, I was also wondering how to move the JFrame on the screen if the
    undecorated property is set to true since there is not Border to select the
    JFrame to initiate the Move.
    Thanks!

    yes... setSize(), setLocation().
    And if you want the user to be able to do it with the mouse, you need to add a border to the rootpane to prevent anyone adding things over the whole rootpane, and add a mouse listener to it to catch mouse click and drag events and do the calculations.
    If you look at the BasicInternalFrameUI, or some thing in there should have some code that does the same thing.

  • Is it possible to disable the minimize, maximize and close on a Frame?

    Is it possible to disable the minimize, maximize and close buttons on a Frame?
    Is it possible to make invisible, minimize, maximize and close buttons of the frame?
    What methods would I use to do so?
    Thank You

    The minimize, maximize and close buttons are defined as the windows decoration. To disable the windows decoration,frame.setUndecorated(true);The setUndecorated() method can only be called while the frame is not displayable.
    Then you can redesign the look and feel of the rootpane and call
    frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);

  • How to capture the event on changing focus from a JTextField?

    Hi All,
    I have got a problem...
    I want to do something (say some sort of validations/calculations) when I change the focus by pressing tab from a JTextField. But I am not able to do that.
    I tried with DocumentListener (jtf01.getDocument().addDocumentListener(this);). But in that case, it's calling the event everytime I ke-in something in the text field. But that's not what I want. I want to call that event only once, after the value is changed (user can paste a value, or even can key-in).
    Is there any way for this? Is there any method (like onChange() in javascript) that can do this.
    Please Help me...
    Regards,
    Ujjal

    Hi Michael,
    I am attaching my code. Actual code is very large containing 'n' number of components and ActionListeners. I am attaching only the relevant part.
    //more codes
    public class PaintSplitDisplay extends JApplet implements ActionListener
         JFrame jf01;
         JPanel jp01;
         JTextField jtf01, jtf02;
         //more codes
         public void start()
              //more codes
             jtf01 = new JTextField();
              jtf01.setPreferredSize(longField);
              jtf01.setFont(new Font("Courier new",0,12));
              jtf01.setInputVerifier(new InputVerifier(){public boolean verify(JComponent input)
                   //more codes
                   System.out.print("updating");
                   jtf02.setText("updated value");
                   System.out.print("updated");
                   return true;
              //more codes
              jtf02 = new JTextField();
              jtf02.setPreferredSize(mediumField);
              jtf02.setEditable(false);
              jp01.add(jtf02, gbc);
              //more codes
              jf01.add(jp01);
              jf01.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              jf01.setVisible(true);
              //more codes
         public static void main(String args[])
              PaintSplitDisplay psp = new PaintSplitDisplay();
              psp.start();
         public void actionPerformed(ActionEvent ae)
              //more codes
    }As you can see I want to update the second JTextField based on some calculations. That should happen when I change the focus from my frist JTextField. I have called jtf02.setText() method inside InputVerifier. But it's giving error...
    Please suggest...
    Ujjal

  • How can we deal with Button group

    hi,
    i was wondering how can we add a listener to the buttons in abutton group,i have a buttongroup,2 textfields for totals and button"submit" and "update".what i wanted is when i press on submit,then teh button taht was selcted in buttongroup should be taken stored and if its male add 1 to maletotal ,or femaltotaland dispalyed in teh textfileds below and when i press "update" the item taht was selected should be wriiten in a file "gen" with the totals too..for thsi purpose i w rote the code as....
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.event.*;
    import javax.swing.BoxLayout.*;
    import java.text.*;
    import java.util.*;
    public class gender1 extends JFrame implements ActionListener
    JPanel buttonpanel=new JPanel(),
    private JPanel mainpanel=new JPanel(new BorderLayout());
    private JButton Submit=new JButton("SUBMIT");
    private JButton Update=new JButton("Update");
    private JRadioButton gender[]=new JRadioButton[genderOptions];
    private String genderlabels[]={"female","male"};
    private JTextField malefield=new JTextField(10),
    femalefield=new JTextField(10);
    public gender1()
              this.getContentPane().setLayout(new BorderLayout());
              updatetotal();
              initGender();
    public void updatetotal()
    //adding buttons and actionlisteners
    lpanel.add(Update);
    Update.addActionListener(this);
    lpanel.add(Submit);
    Submit.addActionListener(this);
    //adding textfileds for totals
    lpanel.add(totmale);
    lpanel.add(totfemale);
    mainpanel.add(lpanel,"Center");
    public void initGender()
    buttonpanel.setBackground(Color.red.darker());
         buttonpanel.setLayout(new BoxLayout(buttonpanel,BoxLayout.X_AXIS));
         for (int k = 0;k < genderOptions;k++)
         gender[k]=new JRadioButton(genderlabels[k]);
    buttonpanel.add(gender[k]);
    optGroup1.add(gender[k]);
         mainpanel.add(buttonpanel);
         gender[0].setSelected(true);
    //get teh one button which is selected
    gender[].addActionlistener(this);
    public void actionPerformed(ActionEvent e)
    if (e.getSource==Update)
    if(gender[].getSelected()=="male")
    int mtot,ftot=0
    mtot=tot+1;
         int maletotal=maletotal+mtot;
    else
    ftot=ftot+1;
    int femaletotal=femaletotal+ftot;
    femalefield=totfemale.setText(femaletotal);
    malefield=totmale.setText(maletotal);
    if(e.getSource==submit)
    DataOutputStream dos=new DataOutputStream(FileOutputStream(gen))
    dos.writeInt(maletotal);
    dos.writeInt(femaletotal);
    public static void main(String s[])
    gender c=new gender();
    c.setSize(800,600);
    c.setVisible(true);
    c.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e)
    { System.exit(0);
    Is this the way to deal it?????

    I use something like this in one of my GUI's
    boolean female = false;
    add a listener to the radio buttons and toggle the flag between true and false;
    set the radio button to male as selected or female which ever is pc at the moment.
    Jim

Maybe you are looking for

  • How to map IDoc segment with qualifiers

    Hi everyone! I have the following problem: In an IDoc of type DESADV01 there can be several segments of type E2EDS01. Each segment has a different qualifier, which is the value of the field SUMID in this case. My target structure (type EDIFACT) now h

  • 810 Black update??

    What exactly is in the black update and why isn't it available for Lumia 810???

  • Can't install v3.6 from v 3.06 om Mac OSX 10.4.11

    I'm trying to update Firefox to v 3.6 from 3.06 but I can't get it to work at all. Do I need to uninstall the original version? Every time I download the update I keep getting the original version Any Ideas?

  • Error creating Objects with Reflection

    This is the code: try{      System.out.println("Restart - test 1 - sub == " + sub);      c = Class.forName(sub);      con = c.getDeclaredConstructor(); catch(NoSuchMethodException e){      System.out.println("Unknown event type\t" + e); }Output: Rest

  • Does Pathfinder "subtract" simply not work anymore?

    Hi all. I'm trying a punch a simple circle out of a filled rectangle, but it does not appear to work.  I select first the circle, then the rectangle, then use Pathfinder's "subtract" option.  All I get is a warning and no visible result.  I'm trying