Performing KeyEvent on a Swing Component

How do I perform a KeyEvent (e.g. 'ENTER or '\n' on a swing component? or Mnemonice such as Alt-M to select a specific Menu option?

StanislavL wrote:
..You can use e.g. public synchronized void keyPress(int keycode) method of Robot class. Or if there is associated key binding you can get ActionMap of the component and find proper action then fire it.Given Robot is restricted to trusted/no security manager apps, using a key binding (if possible) seems the better solution.
Edit 1: added (..) caveat.
Edited by: Andrew Thompson on Mar 16, 2011 6:31 PM

Similar Messages

  • Swing component fires an event to non-GUI code

    Hi all -- this is my first post in forums.sun.com.
    Question to get me started -
    I have a Swing component that fires an ActionEvent. I would like that ActionEvent to trigger code that does not run on the AWT Event Queue thread (some code that will take some time without impacting GUI rendering performance.)
    I know I could put that Event's action command into a synchronized Queue, and have a worker thread checking the queue and taking action when it finds a command there. Likewise, I could flag a volatile boolean as true, and have a worker thread check the flag and take action when true.
    Or (and I suspect this is best), I could create a new SwingWorker thread right in actionPerformed().
    Any opinions on what makes sense?

    pkwooster: Yep. That's what I meant.
    As for the design pattern, Observer was the pattern I was intending to use (and have already implemented). Would anyone argue that another method is more efficient or "correct"?
    My sample project is:
    Business Object -> Main Dialog -> Embedded Dialog
    The Main Dialog contains no business logic - just simple navigation events. The Embedded Dialog contains the real controls and reports any interaction using Swing events, which the Main Dialog picks up.
    I then set up the Observer pattern between the Main Dialog and the Business Object.

  • Help-using document as a java swing component

    Hi,
    can i use a document excel file or a doc file as a swing component.
    i have few templates in in excel and .doc format.
    i use them to produce bills by just entering data.
    Now i want to develop a swing application and use the same templates in jpanel or jtextpane or jeditorpane.
    its very hectic to make templates in swing using tables and all.
    is there any api which can help me out???
    thanks

    as a Swing component? No.
    There's probably libraries for reading those types of files, and maybe displaying them. POI, perhaps?

  • Swing component's margin in a frame

    Hello all,
    When you set the bounds of a Swing component in a frame, it will automatically apply those bounds to the VISIBLE part of the frame, so that, a Y value of 0, for example, will not be at the very top of the frame, but right underneath the title bar of the frame. If you give a regular AWT a value of 0 to it's Y coordinate, part (or all) of it will be covered by the title bar of the frame. This does not happen with Swing components, which automatically add the height of the title bar to the value you give to their Y coordinate.
    Now, what I want to know is, how can I retrieve the value of that "automatic margin"?. How can I know the number of pixels that the Swing component is being slided down, in order to save the title bar of the frame? This value can not be constant, since it will differ from one platform to another, and from one Look 'n Feel to another, but I have not been able to find out the way to get the value that it's being applied in each case.
    As allways, many thanks in advance for your help.

    Don't know if there is any direct way to get this information. But, assuming the border width/height is equal on all four sides you could try something like:
    Dimension frameD = frame.getSize();
    Dimension contentD = frame.getContentPane().getSize();
    int borderWidth = frameD.width - contentD.width;
    int titleHeight = frameD.height - contentD.height - borderWidth;

  • How to set a Swing component as Modal window on a SWT Component.?

    How to set a Swing component as Modal on a SWT Component.I mean, I have a window (SWT Container) with some menu items.
    When I click on one menu item then i will get one new Swing Window.
    When creating the new frame I had passed Modal value as TRUE in the constructer.Now child is not behaving as Modal Window.I mean I am able to go to parent window even though the child window is opened as a Modal Window.This is only happened when I double click on the Title Bar of the Parent Window.
    If I try to click on any other part of the Parent Window except Title bar ... the child window is working as a Modal Window.
    Can any one suggest me to solve this one !!

    int this case, do this :
    JFrame f = new JFrame("Authentification");
    f.getContentPane().setLayout(new BorderLayout());
    f.getContentPane().add(myJPanel, BorderLayout.CENTER);
    f.setBounds(x,y,w,h);
    f.setVisible(true);
    Where myJPanel is the Panel you developped.

  • How to set a Swing component as Modal on a SWT Component?

    How to set a Swing component as Modal on a SWT Componen?.I mean, I have a SWt Component window and from that window I am displaying a SWING Component Modal window.
    The problem is my swing window is not working as Modal always.
    When I opened the swing window from SWT window,swing window is working as Modal.But if Idouble click on Menubar or Title bar of the SWT Window then my Swing window goes back.If I click on any other part of the SWT window.. then once again Swing window is working as modal.
    Can any one suggest me to solve this?
    I think this is isuue related with Swing over SWT..

    pradeep.rajadurai wrote:
    I want set the JTable as a background of jframe or jinternalframe , how it is possible One way that may work, you can always extract the image from a rendered JTable and then paint the same image into the JPanel that holds your components via it's paintComponent method, then added the JPanel to the app's contentPane.
    give me simple pgmIs English your second language? Because if so, please understand that this demand can be taken by some as rude.

  • Support for Multilingual Numeral Input in JTextField swing component

    When the User Locale is changed from the regional & language options in the control panel and the standard digits are customized to a non Latin character set, all the windows applications adhere to the changes made. HTML also respects the changes in effect and displays any numeric values using the new character set, which are the national digits for many Eastern Locales such as Chinese, Arabic(Saudi Arabia), Urdu and many more. The JTextField swing component given by java, however, does not show any support to the new settings. Any numeric input is displayed in the Latin character set even when the input locale of the system is also changed respectively. Any text input for this case is correctly displayed in the desired literals and appropriate glyphs. However, unlike the AWT components, numeral input and display is not catered as per the user/developer's requirements. This behavior was first noticed in 2007, as far as i have found out, and was reported once again on the same thread in 2010. The thread is given below as a reference. No action or response has been taken. Kindly look into this matter and please let me know if this bug has been reported before and if there is any intent of providing a fix for it.
    Reference: http://www.coderanch.com/t/344075/GUI/java/Multilingual-support-JTextField
    Regards,
    Aitzaz Ahmad
    Software Engineer
    SENSYS

    I too had an itch to reply with something like this
    This is a sign of work well done!
    The WD has so strong UI abstraction, that hides client-server nature applications almost completely. If you search forum, you will even find posts where developers try to upgrade value of ProgressMeter in <b>for</b> loop )
    VS

  • Swing component for awt.canvas

    Hi,
    Can anyone tell me the equivalent SWING component for awt CANVAS. I need it because i need to display only Images (nothing else) on it. If anyone can tell how I can do it.

    JPanel is the Swing-equivalent of java.awt.Canvas, but if you are just displaying images, you can use the JLabel class, which supports use of images as icons (see also ImageIcon class).
    Mitch Goldstein
    Author, Hardcore JFC (Cambridge Univ Press)
    [email protected]

  • Make a PJC Swing component Modal?

    Does anyone know how to keep a PJC that is a Swing component in the same focus as the form?
    In other worsd, when you invoke a spell checker in MS Word the spell check window is in focus when the word window is in focus.
    If a swing component is non modal then it can get lost in the shuffle. Is it possible to force a PJC to be Modal?
    null

    For instance, it looks as though the calendarWidget is non-modal

  • Searching a calendar swing component

    Hello friends.
    I'm looking for a calendar swing component, to make a schedule aplication (like Outlook).
    I found "Mig Java Calendar" (http://www.migcalendar.com/index.php) but it isn't free, i need one like this free.
    Do you know someone free?
    Thank you.

    And if you think, as I do, that a date picker is
    standard component and should be part of the jdk,
    please vote here:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=473
    0041
    -Pucethat is really helpful. I voted for it.

  • How to call Ocx in swing Component

    Hi i want to play Flash4 file xxx.swf in swing Component
    JMF Api Supports upto Flash2 only i downloadled Flash4 player which is a ocx file .how can i integrate this ocx in swing Component
    help me please
    regards
    Mahesh.B

    I have used the tool JacoZoom by InfoZoom (http://www.infozoom.de).
    The tool can create JCWs (java callable wrappers) for COM and ActiveX objects.
    If they are visual, you can create and display them within your Java app
    either as AWT or in Swing.
    In general, JacoZoom is the best tool I have found so far, it is my
    favorite.
    Sylvia

  • My Swing component's style is changed!

    Hi all. I am using Linux openSuse and from a week I see that my swing component's style is changed! JButton, JPanel, JMenu, JCheckBox and other have a different style and I don't know why... this is an example: http://img527.imageshack.us/img527/715/screen1lg1.png
    How can I return on the original swing component's style? Please help :(

    Anybody can help me? :'(

  • Swing component to use as time editor

    what is the Swing component that we can use to immitate clock component editor in windows?
    you know, the list where you can select/edit hours,minutes seconds .... is it a JList
    can somebody give a small example please
    thanks

    Read the tutorial: [How to Use Spinners|http://java.sun.com/docs/books/tutorial/uiswing/components/spinner.html]
    You will find some examples there.

  • Problem in Swing Component (JComboBox)

    Hello i've got one amazing problem in my Swing Component (JComboBox) while testing for Glasspane..
    Please check this photo http://www.flickr.com/photos/39683118@N07/4483608081/
    Well i used Netbeans Drag n Drop Swing so the code might be messing..any way my code looks like this:
    My code looks like this:
    public class NewJPanel extends javax.swing.JPanel {
        /** Creates new form NewJPanel */
        public NewJPanel() {
            initComponents();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            jTextField1 = new javax.swing.JTextField();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jButton1 = new javax.swing.JButton();
            jComboBox1 = new javax.swing.JComboBox();
            jCheckBox1 = new javax.swing.JCheckBox();
            setOpaque(false);
            jTextField1.setText("jTextField1");
            jLabel1.setText("jLabel1");
            jLabel2.setText("jLabel2");
            jLabel3.setText("jLabel3");
            jButton1.setText("jButton1");
            jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
            jComboBox1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
            jComboBox1.setNextFocusableComponent(jCheckBox1);
            jComboBox1.setOpaque(false);
            jComboBox1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jComboBox1ActionPerformed(evt);
            jCheckBox1.setText("jCheckBox1");
            jCheckBox1.setOpaque(false);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
            this.setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(119, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel1)
                        .addComponent(jLabel2)
                        .addComponent(jLabel3))
                    .addGap(51, 51, 51)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jButton1)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jCheckBox1)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(115, 115, 115))
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(70, 70, 70)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel1))
                    .addGap(15, 15, 15)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jCheckBox1))
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addComponent(jButton1)
                    .addContainerGap(93, Short.MAX_VALUE))
            jComboBox1.getAccessibleContext().setAccessibleParent(null);
        }// </editor-fold>
        private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JCheckBox jCheckBox1;
        private javax.swing.JComboBox jComboBox1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JTextField jTextField1;
        // End of variables declaration
    }

    For more help create a [SSCCE (Short, Self Contained, Compilable and Executable, Example Program)|http://sscce.org], that demonstrates the incorrect behaviour.

  • Resizing the wrapped swing component inside the javafx stage

    I have a customized swing component & need to wrap it in javafx stage. But as & when the javafx scene resizes, I want to resize the swing component accordingly.
    One way of resizing this is to scale the swing component. But is there any other way or layout to do it efficiently.
    --Nitin Pokalwar                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Hello
    <p>Let's have a look at this Forms PJC/JavaBean site</p>
    Francois

Maybe you are looking for

  • How do I sync my Microsoft outlook calender to my handled?

    Need some serious help here!  I am brand new user of a PDA (Zire 31.)  I have a microsoft outlook account through my work and I know that I can sync my calender to my handheld, however I cannot figure out how to do so.  Can anyone please point me in

  • Admin and Task servers as one in the same

    I open up the Remote Desktop software, and select 1 computer from the list. I then click on the "Install" icon and drag a .pkg file inside of the "Packages" area. I check off the radio button that says "Run this task from: The Task Server on this com

  • How do I move files in Users/Shared instead of copying?

    I cannot move any files in /Users/Shared, even to other folders within Shared.  Dragging a file or folder in /Users/Shared shows the green "+" copy icon and creates a copy even if I hold down CMD while dragging.  Is this normal behavior?  How do I mo

  • Files deleted from the Library and now internet doesn't work?

    Hello, I'm new here and this is probably going to sound dumb but... my father deleted some files from the Library by mistake and now internet doesn't work in his computer. Everything seems normal, but the webpages don't load (we tried lots of pages a

  • JAX-WS fault ?

    Hello, I tried implementing a simple web service from Weblogic docs (http://e-docs.bea.com/wls/docs103/webserv/use_cases.html#wp220705) When I deploy this WS and test it using Weblogic 10.3's Test Client, I get the following Request/response: Service