Java Swing App hangs on socket loop

H}ello everyone i've run into a bit of a snag with my application, its a simple chat bot right now but will evolve into a chat client soon. I can't do that however since my app hangs when i look through the readLine() function to receive data and i dont know how to fix this error. The code is below.
The doSocket() function is where the while loop is if anyone can help me with this i'd be very greatful.
* GuiFrame.java
* Created on August 13, 2008, 9:36 PM
import java.net.*;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
* @author  brian
public class GuiFrame extends javax.swing.JFrame {
    /** Creates new form GuiFrame */
    public GuiFrame() {
        initComponents();
    Socket client_sock = null;
    PrintWriter out = null;
    BufferedReader in = null;
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
    private void initComponents() {
        convertButton = new javax.swing.JButton();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Test Bot");
        convertButton.setText("Connect");
        convertButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                convertButtonActionPerformed(evt);
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(41, 41, 41)
                .addComponent(convertButton)
                .addContainerGap(42, Short.MAX_VALUE))
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(convertButton)
                .addContainerGap(26, Short.MAX_VALUE))
        pack();
    }// </editor-fold>                       
private void convertButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
    if (convertButton.getText()=="Connect") {
                String old;
                try {
                    client_sock = new Socket("www.spinchat.com", 3001);
                    out = new PrintWriter(client_sock.getOutputStream(), true);
                    in = new BufferedReader(new InputStreamReader(client_sock.getInputStream()));
                } catch (UnknownHostException e) {
                } catch (IOException e) {
            try {
                doSocket();
            } catch (IOException ex) {
                Logger.getLogger(GuiFrame.class.getName()).log(Level.SEVERE, null, ex);
    } else if (convertButton.getText()=="Disconnect") {
        out.println("e");
        out.close();
        try {
            client_sock.close();
            in.close();
        } catch (IOException ex) {
            Logger.getLogger(GuiFrame.class.getName()).log(Level.SEVERE, null, ex);
private void doSocket() throws IOException {
    BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
    String userInput;
    String old;
        while ((userInput = stdIn.readLine()) != null) {
            old = userInput;
            if (userInput != old) {
                String proto = userInput.substring(0, 0);
                if (proto == ":") {
                    out.println("{2");
                    out.println("BI'm a bot.");
                    out.println("aNICKHERE");
                    out.println("bPASSHERE");
                } else if (proto == "a") {
                    convertButton.setText("Disconnect");
                    out.println("JoinCHannel");
    * @param args the command line arguments
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GuiFrame().setVisible(true);
    // Variables declaration - do not modify                    
    private javax.swing.JButton convertButton;
    // End of variables declaration                  
}Edited by: briansykes on Aug 13, 2008 9:55 PM
Edited by: briansykes on Aug 13, 2008 9:56 PM

>
..i've run into a bit of a snag with my application, its a simple chat bot right now but will evolve into a chat client soon. >Is this intended as a GUId app? If so, I would stick to using a GUI for input, rather than reading from the command line (which when I run it, is the DOS window that jumps up in the BG - quite counterintuitive). On the other hand, if it is intended as a non-GUId or headless app., it might be better to avoid any use of JComponents at all.
My edits stick to using a GUI.
Other notes:
- String comparison should be done as
s1.equals(s2)..rather than..
s1 == s2- Never [swallow exceptions|http://pscode.org/javafaq.html#stacktrace] in code that does not work.
- Some basic debugging skills are well called for here, to find where the program is getting stuck. When in doubt, print out!
- What made you think that
a) a test of equality on a member against which you had just set the value to the comparator, would logically lead to 'false'?
old = userInput;
if (userInput != old) ..b) A substring from indices '0 thru 0' would provide 1 character?
String proto = userInput.substring(0, 0);
if (proto == ":") ..
>
..if anyone can help me with this i'd be very greatful.>Gratitude is often best expressed through the offering of [Duke Stars|http://wikis.sun.com/display/SunForums/Duke+Stars+Program+Overview].
* GuiFrame.java
* Created on August 13, 2008, 9:36 PM
import java.net.*;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
* @author  brian
public class GuiFrame extends JFrame {
    /** Creates new form GuiFrame */
    public GuiFrame() {
        initComponents();
    Socket client_sock = null;
    PrintWriter out = null;
    BufferedReader in = null;
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
        convertButton = new JButton();
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setTitle("Test Bot");
        convertButton.setText("Connect");
        convertButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                convertButtonActionPerformed(evt);
        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(41, 41, 41)
                .addComponent(convertButton)
                .addContainerGap(42, Short.MAX_VALUE))
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(convertButton)
                .addContainerGap(26, Short.MAX_VALUE))
        pack();
        setLocationByPlatform(true);
    }// </editor-fold>
private void convertButtonActionPerformed(java.awt.event.ActionEvent evt) {
    if (convertButton.getText()=="Connect") {
                String old;
                try {
                    System.out.println( "Connect start.." );
                    client_sock = new Socket("www.spinchat.com", 3001);
                    out = new PrintWriter(client_sock.getOutputStream(), true);
                    in = new BufferedReader(new InputStreamReader(client_sock.getInputStream()));
                    System.out.println( "Connect end.." );
                } catch (UnknownHostException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
            try {
                doSocket();
            } catch (IOException ex) {
                Logger.getLogger(GuiFrame.class.getName()).log(Level.SEVERE, null, ex);
    } else if (convertButton.getText()=="Disconnect") {
        out.println("e");
        out.close();
        try {
            client_sock.close();
            in.close();
        } catch (IOException ex) {
            Logger.getLogger(GuiFrame.class.getName()).log(Level.SEVERE, null, ex);
    private void doSocket() throws IOException {
        System.out.println( "doSocket start.." );
        String userInput;
        String old;
        userInput = JOptionPane.showInputDialog(this, "Send..");
        while(userInput!=null && userInput.trim().length()>0) {
            System.out.println( "doSocket loop 1.." );
            String proto = userInput.substring(0, 1);
            System.out.println("proto: '" + proto + "'");
            if (proto.equals(":")) {
                System.out.println("Sending data..");
                out.println("{2");
                out.println("BI'm a bot.");
                out.println("aNICKHERE");
                out.println("bPASSHERE");
            } else if (proto.equals("a")) {
                convertButton.setText("Disconnect");
                out.println("JoinCHannel");
            userInput = JOptionPane.showInputDialog(this, "Send..");
        System.out.println( "doSocket end.." );
    * @param args the command line arguments
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GuiFrame().setVisible(true);
    // Variables declaration - do not modify
    private JButton convertButton;
    // End of variables declaration
}

Similar Messages

  • Java Swing apps cause Windows 2K to hang

    I have an IBM clone machine running a P4 and Windows 2k that hangs whenever I try to exit out of a window in a Java swing app. Whether the window is the main application window or a menu window instantiated by the application to be a child of the main window, does not matter. It hangs regardless. I have tried multithreaded apps and they do not cause my windows machine to hang. Neither do simple swing apps. But any multithreaded swing app causes it to hang. JEdit causes it. Forte causes it. I am running Java 1.4.1. Thanks for any help in this.

    Freezes under Java 1.4.1 with Windows
    Posted on Dec 14, 2002 - 02:57 PM by slava
    Installation This is turning into a FAQ, so I thought I'd post it on the community site. A lot of people have complained that jEdit can hard freeze their windows system after upgrading to Java 1.4.1. If you experience this, the problem is not with jEdit, but with your video driver. Updating the driver to the latest version should solve the problem; downgrading to Java 1.4.0 might also work.
    http://community.jedit.org/modules.php?op=modload&name=news&file=article&sid=190&mode=thread&order=0&thold=0

  • Expandable Menu in Java Swing app

    Hello JFriends,
    is it possible to create a expandable menu in java swing app? I am thinking of something like menu in MS Visio: http://img32.imageshack.us/i/menuip.jpg/
    It works like that: When user click on a bar it expands (with nice animation) and shows containing components.
    Or maybye there are components like that?
    Thanks in advance for Your reply and please forgive me if my english is bad.
    JRegards :-)

    Yes, such constructs are possible. There isn't a pre-made component exactly like that. The NetBeans IDE has a Window - named Palette - that's very similar. The code is open source.
    You can read about Java menus here:
    [http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html]

  • JAVA / SWING apps, font AA / LaF KDE 4.3

    Hi Everyone,
    I know the title is terrible, but here is my problem:
    I am using Netbeans for most of my development projects. I am very happy with it; however, the look and feel of Netbeans (and most other Java apps, such as FreeMind for example) is appalling and does not integrate into my KDE 4.3 desktop at all. I understand that you can start netbeans with certain options to change the look and feel to GTK, but the fonts still look jagged.
    I followed this forum post http://bbs.archlinux.org/viewtopic.php?id=72892 and tried to set the JRE / JAVA options globally, so that all java apps start with GTK laf and AA. However, non of the methods described work / netbeans overrides them (?).
    But really, the biggest problem are the ugly fonts. Java / SWING apps do not seem to recognize my KDE settings for AA and font style at all. And non of the Cl options work to fix it.
    Does anyone have any tips or tricks to fix any of these issues I am having with the combination Java / Swing / KDE / NB?
    Running:
    Archlinux (duh)
    KDE 4.3 / qt-gtk-engine
    sun-jdk 1.6uX
    Netbeans 6.7.1
    Thanks!
    KnY

    I added what I knew about improving Sun java fonts to the wiki:  http://wiki.archlinux.org/index.php/Jav … _-_Sun_JRE.  You may want to try other fonts than B&H's Lucida.  See the section in the wiki article about changing the default fonts by editing 'fontconfig.properties'.

  • Java swing dynamic forms (in a loop)

    Hi All,
    Is it possible to dynamically create forms using java swing? What I mean to ask is that if I have the necessary information in a table, like the label and a corresponding text field, I can loop through and create the required number of fields. If I do it this way and when the users add text, will I not lose the ability to access each JTextField through its own variable? Is this possible? Basically, I need to be able to access each field through its own variable to do some additional validations on the text entered, etc. Please let me know, if it is possible through java swing.
    Any help in this regard is greatly appreciated.
    Thanks.

    mrbean1975 wrote:
    ..Is it possible to dynamically create forms using java swing? If by java swing you mean Java Swing, then yes.

  • Running java swing apps thru telnet... [Is this possible?]

    Hi All!
    I am just wandering if it is possible to run swing applications thru telnet since everytime I run it... it returns ang error....
    Exception in thread "main" java.lang.NoClassDefFoundError: sun/awt/X11GraphicsEnvironment
    at java.lang.Class.forName1(Native Method)
    at java.lang.Class.forName(Class.java:173)
    at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:90)
    at at sun.awt.motif.MToolkit.<clinit>(MToolkit.java:109).null(Unknown Source)
    at java.lang.Class.forName1(Native Method)
    at java.lang.Class.forName(Class.java:173)
    at java.awt.Toolkit$2.run(Toolkit.java:754)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:745)
    at javax.swing.ImageIcon.<init>(ImageIcon.java:226)
    at javax.swing.LookAndFeel$1.createValue(LookAndFeel.java:295)
    at javax.swing.UIDefaults.getFromHashtable(UIDefaults.java:203)
    at javax.swing.UIDefaults.get(UIDefaults.java:148)
    at javax.swing.MultiUIDefaults.get(MultiUIDefaults.java:65)
    at javax.swing.UIDefaults.getIcon(UIDefaults.java:429)
    at javax.swing.UIManager.getIcon(UIManager.java:562)
    at javax.swing.plaf.basic.BasicOptionPaneUI.getIconForType(BasicOptionPaneUI.java:600)
    at javax.swing.plaf.basic.BasicOptionPaneUI.getIcon(BasicOptionPaneUI.java:586)
    at javax.swing.plaf.basic.BasicOptionPaneUI.createMessageArea(BasicOptionPaneUI.java:337)
    at javax.swing.plaf.basic.BasicOptionPaneUI.installComponents(BasicOptionPaneUI.java:178)
    at javax.swing.plaf.basic.BasicOptionPaneUI.installUI(BasicOptionPaneUI.java:146)
    at javax.swing.JComponent.setUI(JComponent.java:475)
    at javax.swing.JOptionPane.setUI(JOptionPane.java:1725)
    at javax.swing.JOptionPane.updateUI(JOptionPane.java:1747)
    at javax.swing.JOptionPane.<init>(JOptionPane.java:1710)
    at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:832)
    at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:646)
    at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:617)
    at JTest.main(JTest.java:40)
    Source Code:
    import javax.swing.*;
    import java.awt.*;
    public class JTest extends JFrame{
    JPanel pnlMain = new JPanel();
    JLabel lblMsg=new JLabel("This is only a test.");
    Font font=new Font("Arial", Font.BOLD, 28);
    public JTest(){
    try{
    this.setTitle("Unix Frame Testing");
    this.setBounds(10,10,500,100);
    this.setVisible(true);
    this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
    lblMsg.setFont(font);
    lblMsg.setBounds(100,10,250,50);                    
    pnlMain.setLayout(null);
    pnlMain.add(lblMsg);
    this.setContentPane(pnlMain);
    }catch(Exception e)
    { System.out.println("Unable to Display Window.");
    JOptionPane.showMessageDialog(null,"Unable to Display Window.","Error",JOptionPane.INFORMATION_MESSAGE);
    System.exit(0);
    public static void main(String args[]){
    JTest test=new JTest();
    }

    "scripts" are entirely different from GUI applications. What do you expect to happen when you run a Swing application through telnet on another machine? Do you expect the Swing UI to be magically transported to the local Windows machine?
    Not gonna happen. Yes, like ejp hinted, you could run an X-environment on your local machine and have the Swing UI tunnel its output there, but are you sure you want GUI apps to run on a remote machine like that? It's not gonna be fun to work with, I'll tell you that.
    Why not create a Java WebStart app (or perhaps even an applet) out of your application, so your users can run the application locally?

  • Java swing app distribution & setup

    We developed a java swing standalone app. How you guys distribute this kind app to end users if they know little about app setup(like data entry clerks).
    We like to generate an executable file bundling the app and JRE for our clients. They just run this executable to detect if there is no JRE on the local machine then install it, and then install the app and setup all environment variables. Is there any tool to do this?
    Thanks.

    If all you need to do is package the JRE with the app and install, then an installation tool like ZeroG InstallAnywhere would be a very good solution.
    If all you need to package, install and automatically deploy updates, you can probably cobble together an installer that uses Java Web Start. Note that in addition to the JRE, you will also need ensure that Web Start is installed.
    If you need to package, install, update, rollback, report, monitor, receive error alerts, and otherwise manage the application, you probably need DeployDirector, in which case, I encourage you to evaluate DeployDirector at http://www.sitraka.com/software/deploydirector/
    And yes, both InstallAnywhere and DeployDirector will allow you to deploy and manage a client-side app that communicates with a database and reads and writes from files on the client -- neither of these tools enforce the sandbox. Java Web Start will require you to either sign the application, or or use the JNLP API.
    Sonal Champsee
    [email protected]
    DeployDirector Product Manager
    Sitraka (now part of Quest Software)

  • Launching Swing apps in foreground remotely

    We have an agent that runs on our machines waiting to start and stop java applications, but there is a problem when the application has a GUI element to it. We are using the RunTime classes and it executes applications in the background which means that GUIs cannot be seen even though they are running.
    What is the secret to automatically launching java swing apps in the foreground?
    Thanks in advance.

    Replying to myself, as I think I've just found the answer (at least for an windows environment)
    --> Just start your app with "javaw" instead of "java"
    (What would be the right way to do it in Linux, for instance?)
    Joao Clemente

  • In program written with Java Swing, I can't input Chinese

    In program written with Java Swing, I can't input Chinese.
    But if I change my language first, then change the input method tu U.S, open the Java Swing application, finally I can input Chinese. I want to know how to fix this bug.
    My OS is Mac OS X 10.6.8.
    At the JDK version 1.6.0_29, I can input Chinese friendly in Java Swing applications. But after 1.6.0_31, I can't do it anymore. The input methods can input Chinese in other non Java Swing applications so the problem must create by JDK or JRE's Swing part. What's the different between 1.6.0_29's Swing and 1.6.0_31's ? Why ? I heard that Java Swing apps not support Chinese input methods seens 2009... Why haven't fix these yet?

    Chazza wrote:
    Perhaps you need to change your keyboard layout in Xorg?
    https://wiki.archlinux.org/index.php/Ke … ard_layout
    Thanks for your answer!
    I have tried to change the keyboard layout from "en" to "cn", but it is still not work.
    The input method coin on the righttop is right when I change the method.But it still output english even I use ibus-pinyin.There is not a box for my choosing chinese words.
    Last edited by Dilingg (2015-05-15 16:18:43)

  • Launching report from Swing app

    How do you launch a report froma Java Swing app and how does the report get viewed and then saved?
    Thanks.

    hello,
    there are several ways of running a report.
    a) by executing rwrun
    b) by submitting an HTTP request to the reports server
    c) by executing rwcli to submit a request to the reports server
    the output has to be viewed using either a browser window.
    regards,
    the oracle reports team --pw                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Performance issue Java Swing under Windows 7

    Hello,
    we have MDI Java Swing application running under Window7. We got a big problem with performance in MDI Windows using AERO.
    Exist any way for Java to tell Win7 that it should not use Aero??
    Thank you,
    David.
    Edited by: 969767 on 6.11.2012 3:33

    If you try to open properties dialog for application (or app shortcut) there you can see "Compatibility" tab and there is check box "Disable visual themes". If we disable this theme our java swing app is very better performance under Windows 7. We need to disable visual theme via java code, if it is possible...
    Thanks.

  • Problem with java swing button and loop

    Problem with java swing button and loop
    I�m using VAJ 4.0. and I�m doing normal GUI application. I have next problem.
    I have in the same class two jswing buttons named start (ivjGStart) and stop (ivjGStop) and private static int field named Status where initial value is 0. This buttons should work something like this:
    When I click on start button it must do next:
    Start button must set disenabled and Stop button must set enabled and selected. Field status is set to 1, because this is a condition in next procedure in some loop. And then procedure named IzvajajNeprekinjeno() is invoked.
    And when I click on stop button it must do next:
    Start button must set enabled and selected and Stop button must set disenabled.
    Field status is set to 0.
    This works everything fine without loop �do .. while� inside the procedure IzvajajNeprekinjeno(). But when used this loop the start button all the time stay (like) pressed. And this means that a can�t stop my loop.
    There is java code, so you can get better picture:
    /** start button */
    public void gStart_ActionEvents() {
    try {
    ivjGStart.setEnabled(false);
    ivjGStop.setEnabled(true);
    ivjGStop.setSelected(true);
    getJTextPane1().setText("Program is running ...");
    Status = 1;
    } catch (Exception e) {}
    /** stop button */
    public void gStop_ActionEvents() {
    try {
    ivjGStart.setEnabled(true);
    ivjGStart.setSelected(true);
    ivjGStop.setEnabled(false);
    getJTextPane1().setText("Program is NOT running ...");
    Status = 0;
    } catch (Exception e) {
    /** procedure IzvajajNeprekinjeno() */
    public void IzvajajNeprekinjeno() {  //RunLoop
    try {
    int zamik = 2000; //delay
    do {
    Thread.sleep(zamik);
    PreberiDat(); //procedure
    } while (Status == 1);
    } catch (Exception e) {
    So, I'm asking what I have to do, that start button will not all the time stay pressed? Or some other aspect of solving this problem.
    Any help will be appreciated.
    Best regards,
    Tomi

    This is a multi thread problem. When you start the gui, it is running in one thread. Lets call that GUI_Thread so we know what we are talking about.
    Since java is task-based this will happen if you do like this:
    1. Button "Start" is pressed. Thread running: GUI_Thread
    2. Event gStart_ActionEvents() called. Thread running: GUI_Thread
    3. Method IzvajajNeprekinjeno() called. Thread running: GUI_Thread
    4. Sleep in method IzvajajNeprekinjeno() on thread GUI_Thread
    5. Call PreberiDat(). Thread running: GUI_Thread
    6. Check status. If == 1, go tho 4. Thread running: GUI_Thread.
    Since the method IzvajajNeprekinjeno() (what does that mean?) and the GUI is running in the same thread and the event that the Start button has thrown isn't done yet, the program will go on in the IzvajajNeprekinjeno() method forever and never let you press the Stop-button.
    What you have to do is do put either the GUI in a thread of its own or start a new thread that will do the task of the IzvajajNeprekinjeno() method.
    http://java.sun.com/docs/books/tutorial/uiswing/index.html
    This tutorial explains how to build a multi threaded gui.
    /Lime

  • Java SE 6 update 1 swing apps run slow

    When I first installed JDK6/JRE SE 6, Netbeans 5.5 and 6 (M9) ran beautifully. All GUI Java applications were quite responsive, and I never noticed a speed issue. However, last week Netbeans started running slowly. You could practically see the entire screen being repainted from top to bottom over the course of a second or two. Naturally, this gets quite annoying when attempting to write code since everytime I scroll, I have to wait a second for the screen to repaint itself. At first I thought this was just a Netbeans issue, but I notice that every other Java GUI app also repaints very slowly. I've been trying to think back as to what could possibly have changed in my system to cause things to run slowly, but can't think of anything.
    I tried reinstalling the JDK and JRE (as well as Netbeans), but it does not seem to have fixed the issue. The reason I'm posting this under the Swing forum is because I suspect this is a Swing issue -- applications that I have written that do not utilize a GUI seem to run at the same speed as before.
    Any suggestions as to what might be causing this slowness?

    could it freezing be related to my delay in updating it ?
    Message was edited by: Sheepo39

  • Swing app keyboard stops working, mystery ESCAPE keystrokes appear in EDT

    Java 6 Swing app. In our development environment, works great. In QA, they use it for a bit, type in a text field, click out to a Windows XP/7 app, click back in the text field, and the keyboard stops accepting keystrokes. The mouse continues to work, and the Swing app continues to paint to the screen.
    I hooked up a KeyEventDispatcher to listen to what is going on. I'll post a more verbose log at the end of this post, but the short version is this. When the keyboard hangs, the log shows that 'escape' keys are being sent, though we do not do any keystroke injection in our app, ESCAPE or otherwise. Nothing on the Swing app can be determined visually to have focus.
    Just before the app starts hanging, it has a side effect of not being able to be brought into the foreground by clicking on it, if, for example, one was working with Excel or Notepad, then try to click on the JFrame title of the app, or anywhere else on the app frame/internals. Once this condition happens, moving away to another Windows app, then going back to the Swing app, causes the keyboard to stop working and the KeyEventDispatcher to see 'escape' keystrokes being sent out.
    Connecting remotely to the app via JVisualVM/JConsole does not show any of the threads hanging/blocked.
    Sometimes you can work for hours before seeing this problem, and other times, you can start the app up and it happens right away. Once it happens, sometimes you can't recover, and sometimes you can click on a button on a navigator panel on the left side that displays an info panel on the right side, and you can start typing again in text fields.
    Once this problem happens, you can start (or have already running) a completely different Swing app (ex.: StackTrace), and the keyboard will stop working for that app too, even though its running in its own separate VM.
    This problem (ALMOST!) always happen when typing in a Swing text field (JTextField, JTextArea, etc.), clicking on and then typing in a Windows text area (Excel cell, Notepad), then clicking back into the Swing app's text field. A few times, we've gotten this to happen by typing in a text field, tabbing to a button, pressing a button, then tabbing/clicking back into the text field, all without leaving the Swing app. But this latter scenario is rare, usually going to/from Swing/Windows XP/7 apps cause the problem to occur more readily.
    The QA computers normally use Citrix to connect and run the app, but this also happens if we run the app completely locally. But again, this only happens to some computers, all of the ones in the QA department; the development computers (the app has not been released into production yet) does not see this problem.
    I had thought that our problem was this problem (Wrong characters in KeyEvents generated from input of barcode scanner but purposely slowing down the acceptance of KEY_PRESSED and KEY_RELEASED events before allowing them to go on to the Swing app (via a KeyDispatcher) did not solve the problem.
    Also, we had thought it might be a Citrix problem and how it (or does it?) hook into the Windows keyboard. The fact that once one Swing app gets into this keyboard doesn't work and escape keys are being sent out by the EDT can affect another Swing app makes me wonder. We're not seeing any VM exceptions either like this (EXCEPTION_ACCESS_VIOLATION - JRE 6.0_23 - Citrix, windows 2003
    Been trying to get this one solved for over a week, but with no luck. Any help/advice would be appreciated. Thank you in advance for your time.
    P.S. Here's the detailed log info I generated via my KeyEventDispatch listener...
    2011-04-01 11:58:17,493 [AWT-EventQueue-1] DEBUG MyKeyEventDispatcher.dispatchKeyEvent:36 - KEY1-keystroke [java.awt.DefaultKeyboardFocusManager@377369]: java.awt.event.KeyEvent[KEY_PRESSED,keyCode=27,keyText=Escape,keyChar=Escape,keyLocation=KEY_LOCATION_STANDARD,rawCode=27,primaryLevelUnicode=27,scancode=1] on javax.swing.JTextField[,320,28,175x18,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.ep.skin.lnf.framework.utils.internal.RoundedBorder@c3a7c0,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],disabledTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],columns=15,columnWidth=11,command=,horizontalAlignment=LEADING]
    2011-04-01 11:58:17,494 [AWT-EventQueue-1] DEBUG MyKeyEventDispatcher.dispatchKeyEvent:42 - KEY2-ActiveWindow: javax.swing.JFrame[mainFrame,128,128,1024x768,invalid,layout=java.awt.BorderLayout,title=My - HQ - 17601,resizable,normal,defaultCloseOperation=DO_NOTHING_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,1024x768,invalid,layout=com.ep.skin.lnf.framework.internal.RootPaneUI$MetalRootLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.BorderUIResource@d0e678,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
    2011-04-01 11:58:17,496 [AWT-EventQueue-1] DEBUG MyKeyEventDispatcher.dispatchKeyEvent:48 - KEY3-CurrentFocusCycleRoot: javax.swing.JFrame[mainFrame,128,128,1024x768,invalid,layout=java.awt.BorderLayout,title=My - HQ - 17601,resizable,normal,defaultCloseOperation=DO_NOTHING_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,1024x768,invalid,layout=com.ep.skin.lnf.framework.internal.RootPaneUI$MetalRootLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.BorderUIResource@d0e678,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
    2011-04-01 11:58:17,497 [AWT-EventQueue-1] DEBUG MyKeyEventDispatcher.dispatchKeyEvent:54 - KEY4-FocusedWindow: javax.swing.JFrame[mainFrame,128,128,1024x768,invalid,layout=java.awt.BorderLayout,title=My - HQ - 17601,resizable,normal,defaultCloseOperation=DO_NOTHING_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,1024x768,invalid,layout=com.ep.skin.lnf.framework.internal.RootPaneUI$MetalRootLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.BorderUIResource@d0e678,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
    2011-04-01 11:58:17,498 [AWT-EventQueue-1] DEBUG MyKeyEventDispatcher.dispatchKeyEvent:60 - KEY5-FocusOwner: javax.swing.JTextField[,320,28,175x18,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.ep.skin.lnf.framework.utils.internal.RoundedBorder@c3a7c0,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],disabledTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],columns=15,columnWidth=11,command=,horizontalAlignment=LEADING]
    2011-04-01 11:58:17,499 [AWT-EventQueue-1] DEBUG MyKeyEventDispatcher.dispatchKeyEvent:66 - KEY6-PermanentFocusOwner: javax.swing.JTextField[,320,28,175x18,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.ep.skin.lnf.framework.utils.internal.RoundedBorder@c3a7c0,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],disabledTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],columns=15,columnWidth=11,command=,horizontalAlignment=LEADING]
    2011-04-01 11:58:17,501 [AWT-EventQueue-1] DEBUG MyKeyEventDispatcher.dispatchKeyEvent:74 - KEY7-stacktrace...
    com..client.util.MyKeyEventDispatcher$StackTraceGenerationException: This exception was created to generate a stack trace, and can be safely ignored.
         at com..client.util.MyKeyEventDispatcher.dispatchKeyEvent(MyKeyEventDispatcher.java:73)
         at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
         at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
         at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Window.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    2011-04-01 11:58:17,504 [AWT-EventQueue-1] DEBUG MyKeyEventDispatcher.dispatchKeyEvent:36 - KEY1-keystroke [java.awt.DefaultKeyboardFocusManager@377369]: java.awt.event.KeyEvent[KEY_RELEASED,keyCode=27,keyText=Escape,keyChar=Escape,keyLocation=KEY_LOCATION_STANDARD,rawCode=27,primaryLevelUnicode=27,scancode=1] on javax.swing.JTextField[,320,28,175x18,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.ep.skin.lnf.framework.utils.internal.RoundedBorder@c3a7c0,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],disabledTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],columns=15,columnWidth=11,command=,horizontalAlignment=LEADING]
    2011-04-01 11:58:17,506 [AWT-EventQueue-1] DEBUG MyKeyEventDispatcher.dispatchKeyEvent:42 - KEY2-ActiveWindow: javax.swing.JFrame[mainFrame,128,128,1024x768,invalid,layout=java.awt.BorderLayout,title=My - HQ - 17601,resizable,normal,defaultCloseOperation=DO_NOTHING_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,1024x768,invalid,layout=com.ep.skin.lnf.framework.internal.RootPaneUI$MetalRootLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.BorderUIResource@d0e678,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
    2011-04-01 11:58:17,507 [AWT-EventQueue-1] DEBUG MyKeyEventDispatcher.dispatchKeyEvent:48 - KEY3-CurrentFocusCycleRoot: javax.swing.JFrame[mainFrame,128,128,1024x768,invalid,layout=java.awt.BorderLayout,title=My - HQ - 17601,resizable,normal,defaultCloseOperation=DO_NOTHING_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,1024x768,invalid,layout=com.ep.skin.lnf.framework.internal.RootPaneUI$MetalRootLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.BorderUIResource@d0e678,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
    2011-04-01 11:58:17,508 [AWT-EventQueue-1] DEBUG MyKeyEventDispatcher.dispatchKeyEvent:54 - KEY4-FocusedWindow: javax.swing.JFrame[mainFrame,128,128,1024x768,invalid,layout=java.awt.BorderLayout,title=My - HQ - 17601,resizable,normal,defaultCloseOperation=DO_NOTHING_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,1024x768,invalid,layout=com.ep.skin.lnf.framework.internal.RootPaneUI$MetalRootLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.BorderUIResource@d0e678,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
    2011-04-01 11:58:17,509 [AWT-EventQueue-1] DEBUG MyKeyEventDispatcher.dispatchKeyEvent:60 - KEY5-FocusOwner: javax.swing.JTextField[,320,28,175x18,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.ep.skin.lnf.framework.utils.internal.RoundedBorder@c3a7c0,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],disabledTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],columns=15,columnWidth=11,command=,horizontalAlignment=LEADING]
    2011-04-01 11:58:17,510 [AWT-EventQueue-1] DEBUG MyKeyEventDispatcher.dispatchKeyEvent:66 - KEY6-PermanentFocusOwner: javax.swing.JTextField[,320,28,175x18,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=com.ep.skin.lnf.framework.utils.internal.RoundedBorder@c3a7c0,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],disabledTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],columns=15,columnWidth=11,command=,horizontalAlignment=LEADING]
    2011-04-01 11:58:17,512 [AWT-EventQueue-1] DEBUG MyKeyEventDispatcher.dispatchKeyEvent:74 - KEY7-stacktrace...
    com..client.util.MyKeyEventDispatcher$StackTraceGenerationException: This exception was created to generate a stack trace, and can be safely ignored.
         at com..client.util.MyKeyEventDispatcher.dispatchKeyEvent(MyKeyEventDispatcher.java:73)
         at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
         at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
         at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Window.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    The above log info repeats multiple times, KEY_PRESSED and KEY_RELEASE, over and over again, for 'escape' keys.
    Edited by: 850693 on Apr 7, 2011 10:16 AM (typo fix)
    Edited by: 850693 on Apr 7, 2011 10:19 AM (Fixed links)

    <discaimer>Don't put too much hope in my reply</disclaimer>
    The only real difference is QA has the Citrix client installed on them, and development does not. You don't need to run our Swing app through a Citrix client though to cause the bug/freezing, just running it on a PC with the Citrix client seems to be enough (in theory). We've been working down a checklist of possible problems/solutions, and we've gotten to the "Install Citrix to the dev PC" item now, so I'll post back if that makes a difference or not in reproducing the problem.
    I've also had QA people actually come over to a dev PC, without the Citrix client, and try to reproduce the problem, and they have not been able to. There's 'something' about their environment vs. ours, but not sure how that would manifest itself as a AWT/Swing keyboard event of mysterious escape keystrokes followed by the locking up on the keyboard, but not the whole Swing app. My personal guess is the Citirix client installing funky Windows-level keyboard driver(s), but I may be totally off on that. /shrugI read your initial post twice and couldn't find out whether you reproduce that on several different machines, so one "environmental" difference comes to mind: have you tried using another keyboard on the defective QA configuration?
    Of course that doesn't explain in itself how the problem would manifest only after switching back and forth to a native Windows app, but then, with the hint that Citrix may make a difference, maybe one driver filters out repeated "Esc" keystrokes, while another doesn't, and that manifests only after a few app switches, and the system event queue, or whatever it's called in Windows, redirects the events to the target app/window?
    Other than that, I wish you had investigated Jeanette's pacemaker hypothesis more... ;)
    Otherwise, yeah. I have a hook in to see all AWTEvent's, but I still need to see/find what's posting the mysterious escape keys to the event queue.I assume it's what you mean, but I'll try to make that clear: you have to investigate, at the OS level, what is posting escape key events to the OS queue.
    I am not a Windows developper, but I seem to understand that the following programs claims to capture keystrokes on the whole screen (not limited to a single window), with some limitations: http://www.codeproject.com/KB/winsdk/WIN_RECORDER.aspx
    More generally, you should search for a Windows way to peek at the Windows' (keyboard?) event queue.
    I'm not sure this could identify which DLL (if it's not originated by the material, see the defective keyboard hypothesis) is posting the events, but that's worth a try (Java for example, would enables to stuff a custom event queue that would trace info about a Java-poster).
    Even if you can't identify the posting DLL, running the "key captuyre" on both the Windows host that has the Citrix window, and the Windows host that you are accessing via Citrix, may give you hints as to where the heck the key strokes originate...
    Good luck, and keep us informed,
    J.

  • Why AWT apps are faster than Swing apps?

    I have written applications using both AWT and Swing. While running under Windows, I feel that AWT apps are much faster and smoother. In contrast, Swing apps fare terribly. Regardless, I can not go back to AWT because of thier limited capabilities.
    I love Java APIs, it is great for programmer. But what about the consumers? Consumers do not care whether it is written in Java or Visual C++?
    I am having a mid-"programming" crisis. I do not want to but, but would be forced to use VC++ for desktop apps abandoning Java.
    I would like to know if you are a serious desktop programmers, what is your motivation for using Java, not VC++ or something?
    Thanks.

    well, for me, it's that one it's Platform Independent. and that does come in handy when your work uses macs instead of normal PCs. Second, it's free to use, unlike VC++ and Pseudo Code (Visual Basic), you don't have to pay unbeleivably large sums of money to get a good compiler. And then there's the whole "Swings Apps are Slower", yes they are, however, if you program them write, they only take a while to initialize, once that is done they run as fast as any Native Program unless you have a tremendous amount of calculations and dynamic generation of components. And also the no Excecutables, true, and... not true, creating a Jar File is almost the same as making a making an EXE, only Jar Files are... platform independent.... and unlike C++ which gives you enough rope to run around the world three times, jump over the moon and hang yourself for actually using it, Java is a clean programming language, not a whole lot of those nasty characters and styles that ugly up your code. at least these are the reasons why i pick Java as the language to come out on top of all others.

Maybe you are looking for

  • Help needed for MySQL 5 database DSN less connection with Oracle reports

    Hi, I am using Oracle Develper Suite and java (J2EE) for my application. I am using MySql 5 as database tool. I want to use Oracle reports of Oracle Develper suite. I have created some reports by first creating system DSN for MySql database and then

  • What is the diffrence between ASCII and BIN mode

    Hello All, What is the diffrence between ASCII and BIN mode Regards, Lisa.

  • Canon Scan to Folder (Server 2008 R2) suddenly doesnt work

    Canon Scan to Folder (Server 2008 R2) suddenly doesnt work We have a few Canon Multi Functionals who have been able to Scan to Folder to our Server 2008 R2 File Server. Since last Windows Updates(13 sep 2012) it doesnt work anymore... Nothing has cha

  • Dtr and sld login issue

    i am connecting to the host network via the vpn. post that when i access the dtr url via the internet explorer i am able to gain access to it. also when i access the sld url viz the internet eplorer i am able to gain access to it. but when NWDS tries

  • Satellite P200 Display is really dim

    My P200 is having display problems (very dim screen). It is just over 1 year old (4 days past 1 year) and I am really not impressed. It works fine with an external monitor. I'm hoping this is not an ongoing problem, as I just recently bought a second