Problem in using swing application

hi friends, iam developed a swing gui in that iam going to give server port number and number of clients handled by the server.Then i press submit button.The action am writed for the submit button is my server program reads the configuration details from the file and then server socket establishes and waits in the accept socket.At this stage,my swing gui gets freezed.... but i dont need that.... coz in that iam using the other button which is used to stop the server program.... can anyone tell me whats the problem and whats the solution?

You need to use a separate Thread for your Socket connection so you don't block the GUI:
http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html

Similar Messages

  • Help! File in use problem when using Swing app

    Hi. I got a program that is pretty much a JFileChooser that prints to standard output the path of the file that I've chosen. If I invoke the DOS command:
    java JFileChooserDemo, I will get the following as expected from the program:
    "You chose a file named: C:\MyJava\Book.xls".
    But if I invoke the following DOS command:
    java JFileChooserDemo > output.txt, the file "output.txt" contains the following:
    "GetModuleHandleA succeed
    LoadLibrary returns baaa0000
    You chose a file named: C:\MyJava\Book.xls"
    So, if I try to open the file or try to modify "output.txt", I get an error message stating that the file is in use.
    What's weird is that, I THINK if I have a program that DOES'NT use Swing or anything GUI-related and prints to standard output with the DOS "> outfile" command, I won't get this problem. So in other words, I can duplicate this problem with a sample Swing application that prints to standard output. Try it yourself.
    In my original program, it does have an event handler that closes the JFileChooser and its container and exits the system via "System.exit(0);", but for some reason, something still has "locked" the output.txt file. I even did the ctr+alt+del and can't find anything that would lock the output.txt file. What's even weirder is that if I run the application again, but output to a different file like "output2.txt", this file is not locked, but the "output.txt" file still is. output2.txt also don't have contain the
    "GetModuleHandleA succeed
    LoadLibrary returns baaa0000" message.
    The only way I know of that would "unlock" output.txt is to re-boot my computer.
    So it seems I have to modify my program somehow because it appears the OS still thinks output.txt file is still in use.
    Someone may think why would I invoke the java interpreter with the DOS "> outfile" command. Well, the reason being, I got a different version of the program that executes a query and I want it to create a delimited text file that contains the resultset of the query, so that I can then import it to Access, Excel, or whatever. But, because of this problem, I can't modify the query result without having to either run the application again and created another file name with the same result or re-boot. Of course, this would be silly.
    Any help in how I can modify my program or any GUI-program so that if I invoke the DOS "> outfile" command, the outfile won't be "locked" would be greatly appreciated. Thanks. If you want my program, you can e-mail me or run any sample program from the Swing Tutorial that prints to standard output and just add the " > outfile" to the java interpreter command.
    -Dan
    [email protected]

    Oops sorry, forgot to add the code. Here it is:
    BTW, can I edit posts? Oh well...
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    public class FileChooserDemo2 extends JFrame {
    static private String newline = "\n";
    public FileChooserDemo2() {
    super("FileChooserDemo2");
    //Create the log first, because the action listener
    //needs to refer to it.
    final JTextArea log = new JTextArea(5,20);
    log.setMargin(new Insets(5,5,5,5));
    log.setEditable(false);
    JScrollPane logScrollPane = new JScrollPane(log);
    JButton sendButton = new JButton("Attach...");
    sendButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    JFileChooser fc = new JFileChooser();
    fc.addChoosableFileFilter(new ImageFilter());
    fc.setFileView(new ImageFileView());
    fc.setAccessory(new ImagePreview(fc));
    int returnVal = fc.showDialog(FileChooserDemo2.this,
    "Attach");
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    /** The next 2 lines I added, the rest of the code is original taken from the Swing Tutorial **/
    System.out.println("You chose a file named: " +
                             fc.getSelectedFile().getPath());
    log.append("Attaching file: " + file.getName()
    + "." + newline);
    } else {
    log.append("Attachment cancelled by user." + newline);
    Container contentPane = getContentPane();
    contentPane.add(sendButton, BorderLayout.NORTH);
    contentPane.add(logScrollPane, BorderLayout.CENTER);
    public static void main(String[] args) {
    JFrame frame = new FileChooserDemo2();
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    frame.pack();
    frame.setVisible(true);

  • Problems After shifting swing application from jdk1.3 to 1.4

    hi,
    i have shifted my Swing application from jdk1.3 to 1.4, some component settings changed in j2se1.4. are listed below
    1). i have added JComboBox to JPanel using BoxLayout, in jdk1.3 it is normal where as in 1.4 comboBox height is increased to panel height.
    Sample code
    (in a Panel)
         setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    add(getYearComboBox());
         add(getMonthNameComboBox());
         add(getDayOfMonthComboBox());
    2). in jdk1.3 the icon which is set to JFrame is visible in the JOptioPane.showConfirmationDialog() also, but in 1.4 the icon is not visible in conformation dialog box.
    Sample Code
    in a JFrame's constructor
    public OptionPaneTest()
    ImageIcon icon = new ImageIcon("icon.gif");
    setIconImage(icon.getImage());     
    setSize(250,100);
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
    setVisible(true);
    JOptionPane.showMessageDialog(this,"hai", "Hai",JOptionPane.WARNING_MESSAGE);
    3). the Labels added to the panel or frame are displaying in light blue color with jdk1.3 and the same label displaying in black with j2se1.3
    Sample Code
    in a JPanel
    setLayout(new BorderLayout(20, 20));
    add(new JLabel("Testing Label Color"), BorderLayout.CENTER);
    please send solution to any or all.
    thanks in advance,
    Pavan.DV

    Thanks for your sugession.
    You realized me by showing the fact that there are no many classes
    Keep suggesting like this.
    I don't even know how to see the API documentation Before you told me.
    Don't take any issue as simple thing and never give foolish suggessions like this.
    If you know the Answer then share it or else musukoni kurcho ra

  • How to generate dynamic HTML pages using Swing Application?

    Hello,
    I am writing a Java application to connect to a local light-weight java database. I would like to generate and present a HTML on the fly after selecting records from a database. At server side, I could easily use JSP/Servlet to do this. How can I do this on a desktop client machine using Java application? I do not want to install Apache web server on the desktop machine. Any help will be greatly appreciated. Thanks in advance.
    Dominic

    The way u need to generate your html pages depened on what u want to generate,
    anyway what i can help with, is how to display a generated page.
    u have to use JEditorPane with HTMLEditorKit and HTMLDocument to display any HTML.
    also u can use the methods provided with the above objects to generate your html format.
    I hope I helped.

  • Problem when using swings with thread

    Hi,
    I am trying to read a database randomly and printing it in a jframe(using jtable and jscrollpane). I am continously checking the values in the database using a infinite do .. while .. loop. and printing the values in the JFrame. I am also making the main thread sleep for every 5 seconds. but when the thread resumes from sleep the JFrame gets the focus. This disturbs me a lot, because of this i am not able to use any other programs like (outlook or word). Kindly provide me a way to continously check the database and print values in the JFrame in the background without JFrame gaining the focus until i click on it.
    Regards
    Kishdude

    It's not clear where you actually tell the JFrame to display itself (usually setVisible(true).
    But this is a bit confused.
    If the first loop is, in fact, infinite then the table will never be created, since the rest of the code won't be reached.
    Don't create a new JTable each time you update the data. Update the existing one. You should define a method, somewhere, to load the table data from the database, call it once while building the window to load the initial values and then - once the window is displayed, set a loop or a Timer going to rescan the data periodically using the same code.
    There are serveral ways you can manage the table data. The key is the TableModel associated with the table. You can change the content of the TableModel or create a new one each time you read the data and use JTable's setModel method to replace it. Personally I'd write a subclass of AbstractTableModel or perhaps DefaultTableModel and put the code to scan the database, plus the data read, in there.
    There's not a lot of point in making the main thread wait once you've openned a window. The program won't exit while it has a window open. You can call setDefaultCloseAction() on the window and tell it to close the program when the close button is clicked. Or you can add a WindowAdapter to the window and deal with the close attempt yourself.
    And don't throw away exceptions in cache clause like you are, because you're never going to debug successfully if you do that. At the very least call printStackTrace() on the exception.
    So your sequence should be (roughly)
    Load the first batch of data into a TableModel.
    Build the window, using the TableModel to create your table.
    display the window.
    Start a background Thread which repeatedly waits a few seconds, then rereads the data into the table model, ensuring it calls the fireTableModelChanged() method of the model that requests that the table be redrawn.

  • Problem while using swing. I need some help

    Whe I am trying to execute the following code (very simple one) my PC hangs up, any ideas about this?!!
    the code is:
    import javax.swing.JOptionPane; // import class JOptionPane
    public class Welcome4 {
    public static void main( String args[] )
    JOptionPane.showMessageDialog(
    null, "Welcome\nto\nJava\nProgramming!" );
    System.exit( 0 ); // terminate the program
    //end of the code

    Hi,
    Your code works fine on my PC. It doesn't hang but come out with expected result.

  • Unable to open/use Blackberry Application World

    Hi everyone,
    I am using BB 9800, Recently I am facing problem to use Blackberry Application world. I already tried almost everything, delete then re-install, re-boot - open battery+memory card -and re-assemble back. those are not work. could anyone help me out? 

    Please tell us why you can't use it.. what happens when you click on the AppWorld icon?
    Or do you NOT see the AppWorld icon?
    Or you do, and what happens, what error messages?
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Problem with "find" mode in adf/swing application

    Hi all,
    I'm working on ADF Swing application which uses MS SQL Server 2005 (JDeveloper 10g 10.1.3)
    I think that my issue might be well-known…sorry if it has been already discussed somewhere else…
    I have a problem with the “find” mode for a detail panel in a master-detail form…(To make it clear the “find” mode is switched on when clicking on the special button on a navigation panel).
    So this mode works well in a master panel, but it demonstrates strange behavior on a detail panel, i.e. it takes me two attempts to find the necessary child object and it doesn’t switch back in a simple way from this mode to the normal mode….say if we are in the department 10 (Dept is a master form) we can’t simply find KING employee (Emp is a detail form)…is there any workaround for this?
    Thanks in advance. Alex.

    Hi Frank, please look this issue

  • Problem in Opening HTML Page in Internet Explorer from my Swing Application

    Hi,
    I am opening a HTML file in Internet Explorer from my swing application.I am using the code given below
    private final static String WIN_FLAG = "url.dll,FileProtocolHandler";
    private final static String WIN_PATH = "rundll32";
    String cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
    // url is HTML file Path
    Process p = Runtime.getRuntime().exec( cmd );
    Here there are two things i need to address ...
    1)The HTML file is opening up,but it always opens behind the swing application,that makes me every time to maximize the HTML file after it being opened up.I want to open it in front of the Swing Application.I need to implement "Always On Top" functionality for the html page.
    2)Whenever i trigger action to open different HTML page,it opens in new Internet Explorer window.
    I need to open it in same IE window.
    how to solve out these problems ??? any help would be greatly appreciated .Thanks in advance.
    - Manikandan

    any idea about this ????

  • Is there any Open source Reporting Toll for using in swing application ?

    Is there any reporting system like crystal report or any thing for report generation. Using JTable class it is so time taking job. I have downloaded Eclipse with crystal report embedded, and have created a report but can not integrate the report with JFrame with any menu item action. All the code i got releted to JSP. and few code get that are using
    //Crystal Java Reporting Component (JRC) imports.
    import com.crystaldecisions.reports.sdk.*;
    import com.crystaldecisions.sdk.occa.report.lib.*;
    //Java Imports.
    import javax.swing.*;
    public class JRCViewReport {
         private static final String REPORT_NAME = "JRCViewReport.rpt";
         public static void launchApplication() {
              try {
                   //Open report.
                   ReportClientDocument reportClientDoc = new ReportClientDocument();
                   reportClientDoc.open(REPORT_NAME, 0);
                   //Launch JFrame that contains the report viewer.
                   new ReportViewerFrame(reportClientDoc);          
              catch(ReportSDKException ex) {     
                   System.out.println(ex);
              catch(Exception ex) {
                   System.out.println(ex);               
         public static void main(String [] args) {
              //Event-dispatching thread to run Swing GUI.  This is good practice for Swing applications
              //to help ensure that events are dispatched in a predicatable order.
              //For more information on using this method, refer to the SUN site below for more details:
              //http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        //Hand-off to worker function to start application.
                        launchApplication();                    
    }Also there is one file ReportViewerFrame.java
    but the error is "*com.crystaldecisions.reports.sdk*" not found
    Please help ..........................................................

    I have already use Jasper Report. Thakns a lot for your suggestion. Now I think i have solved your problem...... View the code.. this code will not open the JasperViewer but from the background it will be printed and after calling the printing function you can save a data in the database ------------------------
    JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
            Connection con = Database.getConnection(); // your database connection
            jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, con);
            for(int i=0;;i++) { //print all pages
                try{
                    JRPrinterAWT.printPages(jasperPrint,i,i,false);
                }catch(Exception e) {
                    break;
            }

  • How to restart swing application by using shotcut key (ex :CTRL+ALT+ENTER)

    Hi,
    Currently my swing application freezs some times, it will not come back, only option i have is restart.
    Can some one can help me how i can implement short cut key (CTRL+ALT+ENTER) that can restart my application. (in any state, my action should allow to restart).
    Thanks
    Anjan
    Edited by: 807057 on Nov 2, 2010 9:16 AM

    Currently my swing application freezs some times, it will not come back,I would work on fixing that problem. Sounds like you aren't using Threads properly and are blocking the EDT. Read the section from the Swing tutorial on [url http://download.oracle.com/javase/tutorial/uiswing/concurrency/index.html]Concurrency for more information.
    how i can implement short cut key (CTRL+ALT+ENTER) that can restart my application.Within Swing this would be done by using "Key Bindings". A section on Key Binding is found on the tutorial link from above. However, is Swing actually is frozen then this won't work.
    Therefore this would need to be done at the OS level, which java doesn't support. You would need to use JNI, which I know nothing about.

  • Memory leakage in Swing application using hash table to retrive data

    Hi I have developed one application using swing , I am using hashtable to retrieve data from database . but that cause me problem my size of application increases automatically for every click in the application.I think memory leakage is there.
    would anybody help me to remove this error

    Hi I have developed one application using swing , I am using hashtable to retrieve data from database . but that cause me problem my size of application increases automatically for every click in the application.I think memory leakage is there.
    would anybody help me to remove this error

  • UI problem when run java swing application on MAC OSX

    Hello,
    I have problem when i run my java swing application on MAC OSX.
    Dialog box is not properly visible in MAC means ita size increses.
    its size incresed and and some content or buttons on that dialog are not fully visible.
    I can only see partial message or button.
    If any one have idea about this problem then give the solution.
    Thanks :)
    Shweta

    I am using following way to create dialog
    JOptionPane optionpane = new JOptionPane(new Object[]{lblMsgUp}, JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, choices, "Save");
    JDialog dialog = optionpane.createDialog(parent, "Save");
    dialog.setSize(450, 125);
    dialog.setVisible(true);

  • Launching another Swing application from existing one using Runtime.exec()

    Hi,
    I have two separate Swing applications, say A and B. I need to launch B from A using Runtime.exec() - essentially I am launching another VM instance from one VM. I am encountering strange problems - B's main window comes up, but GUI doesn't update; sometimes B comes up and GUI updates, but huge memory leaks happen. All the problems with B go away once A is shut down. It almost looks like both the instances of VM are sharing (or competing for) the event thread. Any comments will be of great help. Thanks.
    note: There is no problem launching B if A is a console java application (i.e. no Swing GUI).

    Do you have to have the second application running in a seperate VM (process)? If not completely neccesary, then you can just invoke the static main() of the second class. If the type of the second class isn't known untill run-time, you can use Reflection to invoke the method.
    Miguel

  • Java Swing application problem in Windows vista

    When we execute the Swing application in windows vista environment.
    The look and feel of the swing components are displayed improperly.
    Do we need to put any specific look and feel for windows vista environment or any specific hardware configuration is required to setup windows vista environment.
    Please give some inputs to solve the problem.
    We have tried with the following sample code to run in windows vista.
    * Vista.java
    * Created on December 5, 2006, 5:39 PM
    public class Vista extends javax.swing.JFrame {
    /** Creates new form Vista */
    public Vista() {
    initComponents();
    pack();
    /** 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.
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
    jButton1 = new javax.swing.JButton();
    jToggleButton1 = new javax.swing.JToggleButton();
    jPanel1 = new javax.swing.JPanel();
    jCheckBox1 = new javax.swing.JCheckBox();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTextArea1 = new javax.swing.JTextArea();
    jTextField1 = new javax.swing.JTextField();
    getContentPane().setLayout(null);
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jButton1.setText("Button 1");
    getContentPane().add(jButton1);
    jButton1.setBounds(20, 20, 170, 30);
    jToggleButton1.setText("Togle btn");
    getContentPane().add(jToggleButton1);
    jToggleButton1.setBounds(100, 80, 90, 20);
    jPanel1.setLayout(null);
    jCheckBox1.setText("jCheckBox1");
    jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    jCheckBox1.setMargin(new java.awt.Insets(0, 0, 0, 0));
    jPanel1.add(jCheckBox1);
    jCheckBox1.setBounds(10, 40, 130, 13);
    getContentPane().add(jPanel1);
    jPanel1.setBounds(10, 150, 200, 130);
    jTextArea1.setColumns(20);
    jTextArea1.setRows(5);
    jScrollPane1.setViewportView(jTextArea1);
    getContentPane().add(jScrollPane1);
    jScrollPane1.setBounds(210, 150, 164, 94);
    jTextField1.setText("jTextField1");
    getContentPane().add(jTextField1);
    jTextField1.setBounds(240, 30, 140, 30);
    pack();
    }// </editor-fold>//GEN-END:initComponents
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new Vista().setVisible(true);
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JToggleButton jToggleButton1;
    // End of variables declaration//GEN-END:variables
    }

    When we execute the Swing application in windows
    vista environment.
    The look and feel of the swing components are
    displayed improperly.Improperly means what? You must be aware that Vista's native L&F certainly isn't supported yet.

Maybe you are looking for

  • Flash player 10.3 won't play on some websites OSX10.6 OK on others

    Neither iMac or MacBook will play videos from http://www.vancouversun.com/ using either Safari or Firefox. Either a black or white square is all I get. Videos on http://www.cbc.ca/ and other sites like You-Tube play fine. I've un-installed Flash play

  • Report with Row Edit capability

    When creating a report, what are the components that enable row edit capability. A few basic reports I generate do not have this capability. How would I change an existing report to allow row edits and then linking to a form to edit content. Thanks,

  • SAP-ISU-CRM

    Hi All, I am working in CRM-ISU projects...Kindly let me know any requirements are there in your organisation. I want to apply... My contact details are there at my business card. Regards, Shiv Kumar Edited by: Shiva Kumar on May 5, 2008 4:47 PM

  • Can I create a "floating" toolbar, or customize any of the floating palettes?

    I don't want the toolbar visible because I need it for almost* nothing and I can't accept even a little compromise to the visible length of my writing workspace. So I hide toolbars, formatting bars, rulers, etc., and use key commands instead whereeve

  • Purging of cache

    Hi All, I want to know if the cache get refreshed once we restart the obiee services or we have to manually run the script to purge the cache at regular intervals once database get refreshed. Thanks, Sushil