Problem in java swing programming

Hello
I am developing one project. I which i put one main menu from which user choose various options.
One of the option is associating students with the batch.
As user choose this option, it opens one frame in which user get one comobox containing list of batches that are already announced in the system.
As user choose any of these batch number, i want that frame shows the one JLabel control and one JList control shows list of candidates registered for the course for which selected batch has announced.
For that i put one penal in the frame which implements ActionListener interface and registered this panel as the ActionListener of this batch combobox. As user choose any of the batch from this combobox in the actionPerformed method i call repaint method.
In the paintComponent method of panel i add two control one JLabel and one JList .
But my panel or frame does not show these control.
What should i do.
I also want to know i develop projects in JDK1.2 will it runs on JDK1.3 or JDK1.4
Because i was using JDK1.2 but it had deleted and i now i am unable to get that version.

Here is some good advice. Take time to download a new version of the SDK, it will help you do things more quickly.
To your problem, I believe it is a matter of switching components within the application. To switch components, you need to use the container.remove(Component c) method, and then use container.add(Component c)Finally you need to validate the container and repaint it to show your newly added component. So in all
container.remove(somecomponent);
container.add(anothercomponent);
container.validate();
container.repaint();Hope this helps one way or the other
ICE

Similar Messages

  • 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

  • Placing a telnet session within a java swing program

    I was wondering if there was a way to maybe anchor a telnet session into a JPanel within a Java Swing program. Most of my users end up running a telnet session while using my Swing Program and I was hoping to find a way to bring the two together. If this is possible could someone point me in the right direction (like an online resource) that might show me how to do this.

    You could use sockets and a TextArea and build your own simple telnet application.
    Socket tutorial: http://java.sun.com/docs/books/tutorial/networking/sockets/index.html

  • Facing problem in Java Swing

    Hi Sir,
    I am using a java GUI Object for taking user name and password (in fields of user name and password) and would like to send the information to a server (in the form of Xml file) on the click of 'Ok' button. The database of registered user is stored on server. If the entered users name or passwords are not correct, the server will send a failure notification to the client (terminal where we typed user name and password). If this is successful, it gives a success notification.
    I am doing this using Swings. Also I want all the communication taking place between the server and the client in the form of XML files. being a new to Swings I am facing certain difficulty.
    I will appreciate your suggestions and help in this regard.
    Thanks and regards,
    Sarib

    817439 wrote:
    Could you please tell me under which category I should post this query. I could not find JAVA Swing section anywhetre in forum home.Steps
    1. Determine what it is that you want the database to do and what you want your code to do. This does NOT involve writing code.
    2. Learn JDBC
    3. Write JDBC classes that does ONLY the database functionality from 1. If it has GUI (swing) code then it is wrong.
    4. Unit test it.
    5. Learn Swing
    6. Write GUI (swing) code that uses the code from 3.
    7. Test it.
    There is a forum for JDBC - steps 2,3,4.
    There is a forum for Swing - steps 5, 6, 7.

  • Java swing program

    Windows-based Java program that can perform currency conversion for the user. The program will give the user the ability to enter the desired amount to convert, the currency type to convert from and to and a button to invoke the conversion. The program should also provide the user a separate dialog to set the conversion rates between each possible currency combination. The program should handle conversions between dollars, pounds and euros.
    •     The program must offer the user three ways to submit the conversion request: a button, a menu item (described below), or hit the Enter key after entering the amount in the transfer text field.
    •     The menu item method must display a new dialog with all necessary fields to accomplish the conversion. When complete, the menu item window must disappear and its results will be displayed on the main window.
    •     The text field indicating the amount to convert must allow the user to input the values in units and cents. Also, all display values must be in units and cents.
    •     A separate menu item that opens a dialog must be provided to set the conversion rates. The default values when the program starts should be randomly generated between 1.00 and 2.00. Reverse conversions should be the inverse of the opposite conversion.
    •     The program must also provide a button to select an amount to convert that is randomly generated between 1,000 and 2,000 in units and cents.
    Edited by: chota on Sep 21, 2008 7:38 PM

    you could charge for homework assignments :)) // I would
    dont know why its in the swing section tho... no mention in the assignment task of GUI, just email a CLI application IMHO
    does the poster want a pass / credit / distinction ?? the code will vary and so will the cost....

  • Problem with Java Mail Program

    Hi Everyone...
    Please help me to sort out this problem...
    I am getting this Exception while executing the code pasted below...
    javax.mail.AuthenticationFailedException
    at javax.mail.Service.connect(Service.java:306)
    at javax.mail.Service.connect(Service.java:156)
    at javax.mail.Service.connect(Service.java:105)
    at javax.mail.Transport.send0(Transport.java:168)
    at javax.mail.Transport.send(Transport.java:98)
    at JDCSend.main(JDCSend.java:38)
    It's just a simple java program to send an email using JavaMail API
    import java.io.*;
    import java.util.*;
    import javax.mail.*;
    import javax.mail.event.*;
    import javax.mail.internet.*;
    import java.util.Properties;
    public class JDCSend {
           public static void main (String args[]) {
              try{
                  String from = "[email protected]";
                  String to = "[email protected]";
                   String host = "smtp.yahoo.com";
        // Get system properties
                  Properties props = System.getProperties();
                   props.put("mail.smtp.host", host);
                   props.put("mail.smtp.port", 465);
                   props.put("mail.smtp.auth", "true");
                   props.put("mail.smtp.starttls.enable","true");
        // Get session
                  Session session = Session.getDefaultInstance(props, null);
        // Define message
                  MimeMessage message = new MimeMessage(session);
                  message.setFrom(new InternetAddress(from));
                  message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
                  message.setSubject("Hello, JDC");
                  message.setText("Welcome to the JDC");
        // Send message
                  Transport.send(message);
              catch(Exception e){ e.printStackTrace(); }
    }

    You need to be identified by stmp server :
    // Send message with authentication!
    Transport tr = session.getTransport("smtp");
    tr.connect(MailHost, user, pass);
    message.saveChanges(); // don't forget this
    tr.sendMessage(message, message.getAllRecipients());
    tr.close();
    Read JavaMail Faq please!

  • Creating variables in a java swing program useing event

    This is my code:
    *Old School Calculator
    *@Collin Doering
    *Version 2.00
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class OSC {
         private static void createAndShowGUI() {
              int first = 0;
              int second = 0;
              int third = 0;
              int fourth = 0;
              int fifth = 0;
              int answer;
              System.out.println ("Calculations");
              System.out.println ("-------------");
              JFrame.setDefaultLookAndFeelDecorated(true);
              JFrame frame = new JFrame("OSC");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button1 = new JButton("1");
    button1.setMnemonic(1);
    button1.addActionListener
         new ActionListener() {
              public void actionPerformed (ActionEvent e) {
    first = 1;
    //This is when the error says "Local variable first is accesed from
    with in inner class; needs to be declared final;
                   System.out.println ("first = ");
    JButton button2 = new JButton("2");
    button2.setMnemonic(2);
    button2.addActionListener
         new ActionListener() {
              public void actionPerformed (ActionEvent e) {
                   System.out.println ("Second = ");
    JButton buttonx = new JButton("x");
    buttonx.addActionListener
         new ActionListener() {
              public void actionPerformed (ActionEvent e) {
                   System.out.println ("answer: ");
    JPanel panel = new JPanel(new GridLayout(10,10));
    panel.add(button1);
              panel.add(button2);
              panel.add(buttonx);
              frame.getContentPane().add(panel);
    panel.setBorder(BorderFactory.createEmptyBorder(
    30, //top
    30, //left
    10, //bottom
    30) //right
    frame.pack();
    frame.setVisible(true);
         public static void main(String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    I am trying to create variables so i can make a calculator (right now i only have buttons 1, 1 and multiply). //This is when the error says "Local variable first is accesed from
    with in inner class; needs to be declared final; then when i declare it final it says <identifier expected>. Could some one please help me. thanx.

    Please post code within code tags (press the "code" button).
    Why are you using an inner class? Simplify:
    public class OSC implements ActionListener {
    button1.addActionListener( this );
    public void actionPerformed( ActionEvent e ) {
        if ( e.getSource() == button1 ) . . .

  • How many threads can be created in a java swing program?

    At first, I intend to use Timer to create a 2D plot repeatedly after a certain number of milliseconds. This is for an animation. However, I discover that it takes a lot of time to generate each 2D plot frame ( about 700 milliseconds on a 1.13 MHz computer, this is a complicated plot requiring a lot of computations). So I think I should use SwingWorkers, that means a new thread for each generated graph image. There might be 1000 images to be created, and thus there might be thousands of threads in my programs. I would like to know if there is any limitation on the number of threads generated in a program so that it will be safe, or is it ok to generate as many threads as you want, as long as you follow strictly the syntax of creating threads?
    I would be thankful if someone can give me some advice.

    as there is no restriction in the Language Specification (http://java.sun.com/docs/books/jls/second_edition/html/memory.doc.html#28457) i would think it's theoretically indefinit. of course, it has a maximum because of your memory. ;-)

  • Problem in Java swing

    Hello
    I add panel in the frame.
    In this panel i add two buttons.
    One of these having close label.
    I want that as user click on this label it will close the frame.
    Problem is can i get ref of the frame in which i put this panel, without passing ref. of the frame in the panel.
    Please help

    Check this out :
    btnClose.addActionListener(new ActionListener(){
              public void actionPerformed(ActionEvent e){
              JButton btn = (JButton)e.getSource();
              JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, btn);
              frame.dispose();
              });

  • Need help for connecting Ms Acces with java Swing in Mac OS

    Hi all,
    i need to connect to Ms Access in MAc os through my java swing program.
    Is it possible for accessing Ms access through dsn in Mac OS.
    If Possible which driver shall i use for Establishing Connection with MS Access in Mac OS.
    Suggestion is needed urgently.
    Can anybody help me out regarding this..
    Thanks in advance.
    Regards,
    sreand

    if I don't find a better solution I'll try your 2nd option but what do you mean by "combo" update?
    My understanding is to simply insert the OS 10.5 installation CD, reinstall the OS and the just keep updating it via the OS SSoftware update panel and stop untill I see the scary Java 8 update. Is that what you meant?
    While you can do it that way, the combo update picks up operating system updates through a collection of releases. When dealing with operating system upgrades, I've found using the combo updates to be more reliable than Software Update, as sometimes Software Update doesn't apply updates correctly, and weird things can happen. Doesn't happen often though, thankfully.
    So the OS X 10.5.5 Combo update contains all updates between 10.5.0 and 10.5. The 10.5.8 combo update contains the updates from 10.5 thru 10.8. Here are the updates:
    10.5 combo update: http://support.apple.com/kb/DL692
    10.8 combo update: http://support.apple.com/kb/DL866
    If you go down the combo path, repair permissions before and after doing each update. Then do Software Update for any other non-OS X updates, and don't apply the Java Update 8.

  • Chess: Java Swing problem!! Help need

    Hi, I have just learn java swing and now creating a chess game. I have sucessfully create a board and able to display chess pieces on the board. By using JLayeredPane, I am able to use drag and drop for the piece. However, there is a problem which is that I can drop the chess piece off the board and the piece would disappear. I have try to solve this problem by trying to find the location that the chess piece is on, store it somewhere and check if the chess piece have been drop off bound. However, I could not manage to solve it. Also, I am very confuse with all these layer thing.
    Any suggestion would be very helpful. Thanks in advance

    I wonder if you are biting off a little more than you can chew. This seems like a big project for a beginning coder. Anyway, my suggestions can only be general since we only have general information:
    1) Break the big problem down into little pieces. Get the pieces working, then put them together.
    2) Make sure your program logic is separate from your GUI.
    3) If still having problems, post an SSCCE. See this link to tell you how:
    http://homepage1.nifty.com/algafield/sscce.html
    4) And as camikr would say (and flounder just said): next time, post this in the Swing forum.
    Good luck!

  • 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)

  • Beginning Swing programming problem

    My classmates and I are trying to write a simple Swing program with a single button and a text field that contains the number of times the button has been pressed since the program started. The problem is that in the ActionPerformed method, any changes to the text field ends up with multiple event errors. It will print the count fine to the command prompt, but not the GUI. Any insight would be greatly appreciated.
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    class CounterGUI extends JFrame implements ActionListener
         public int count = 0;
         Container contents = getContentPane();
         JTextField counter;
         final String temp = "Total times pressed: ";
         public CounterGUI()
              final int width = 300;
              final int height = 300;
              setSize(width, height);
              JTextField counter = new JTextField(temp + count);
              counter.setEditable(false);
              JButton clicker = new JButton("Click me!");
              clicker.addActionListener(this);
              clicker.setActionCommand("Click");
              contents.add(counter, "Center");
              contents.add(clicker, "South");
         public void actionPerformed(ActionEvent e)
              String command = e.getActionCommand();
              if(command == "Click")
                   count++;
                   counter.setText(temp + count);     
                   System.out.println(count);
         public static void main(String[] args)
         JFrame f = new CounterGUI();
         f.addWindowListener(new WindowCloser());
              f.setVisible(true);

    Hi Guys,
    The line JTextField counter = new JTextField(temp + count); is declared in the constructor, this means that the field counter is not visible to other methods and you'll get a null pointer exception (NPE) when you try to access the class field counter
    Change to counter = new JTextField(temp + count); Now if you were catching and displaying exceptions you'd notice that this was happening.
    Dave

  • Problem in compiling JAVA SWING

    Dear frens,
    I'm new in java swing. I have some knowledge in developing java in DOS, but dont have any knowledge in developing java in gui. I have write a program but it is unable to compile.
    I compile like this ----> javac HelloWorldSwing.java
    please help me to provide a guide.
    thank you
    regards
    Singaravelan

    import javax.swing.*;
    import java.lang.*;
    public class HelloWorldSwing {
         * Create the GUI and show it. For thread safety,
         * this method should be invoked from the
         * event-dispatching thread
         private static void createAndShowGUI() {
              //Make sure we have nice window decorations.
              JFrame.setDefaultLookAndFeelDecorated(true);
              //Create and set up the window.
              JFrame frame = new JFrame("HelloWorldSwing");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              //Add the ubiquitous "Hello World" label
              JLabel label = new JLabel("Hello World");
              frame.getContentPane().add(label);
         public static void main(String[] args) {
              //Schedule a job for the event-dispatching thread:
              //creating and showing this application's GUI.
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        createAndShowGUI();
    This is my program, i can compile but cannot run the program

  • Problems with JAVA SE 6 in 1 Program.

    Hello, I'm a new guy here, so sorry for mistakes
    Problem that JAVA seems does not work propertly. This is the text from error.log in program that I want to start: "1020=The JVM found at {0} is damaged.\r\nPlease reinstall or define EXE4JJAVAHOME\r\nto point to an installed 32-bit JDK or JRE.". Cause I am not a pro in using mac os I can't understand how to solve this problem. Thank you for your time and answers.
    Best Regards,
    Mantas

    HI,
    Try here. http://developer.apple.com/java/faq/
    Carolyn

Maybe you are looking for

  • How to put detail records in fixed formÉ

    Hi, I am trying to build a crystal report based on an existing printed form. The form includes elements that look like the following: Activity Hot Oiler - 4 mbtu     7mbtu Pressure Pumping - 5K   10K   15K Travel - 5K   10K   15K Standby - 5K   10K  

  • Step-by-Step Guide for connecting CRM with SAP R/3 system Server

    Hi Experts, For my ongoing project , I am in the need of connecting the CRM server with SD server. Can u share any Step- By Step  guide for doing that. I know that  the RFC connection has to be established between the system. Logical system must be c

  • Exporting CS5 file to PDF causes the document size to enlarge on PDF!

    I need help... FAST! I have a 14-page 4CP calendar that bleeds on three sides. The bleed size is 3/16", per the printer's requirements. When I export the file from InDesign to PDF, the overall page size is increased by exactly 3/16"! I nearly missed

  • Queries slow since truncate & imprort

    Hello everyone, We truncated a table then re-imported the data. Now our queries in Forms 6 are VERY SLOW. All other forms are fine. We haven't changed the form at all. Our index's seem the same, but are they still working? Is this because our data is

  • Boris Export Stops at 98%

    Has this ever happened to you? I made up some titles with Boris 3D. Everything looks good. I put it in an NTSC-anamorphic timeline, added a freeze frame so that the last line of text would hold at the end, then exported it as a QT movie. During the e