Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: javax.swing.DefaultComboBoxModel@1a38598

  1. #1
    Member
    Join Date
    Apr 2011
    Location
    Niperia
    Posts
    30
    My Mood
    Amazed
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default javax.swing.DefaultComboBoxModel@1a38598

    Am trying to refresh my ComboBox field with the following code with values from my database:

    	public ComboBoxModel phoneIdCombo(DefaultComboBoxModel model){
    		try{
    			try{
    				Class.forName("com.mysql.jdbc.Driver").newInstance();
    			}catch(Exception e){
    				JOptionPane.showMessageDialog(null, "Exception: "+e.getMessage());
    			}
    			con = DriverManager.getConnection("jdbc:mysql://localhost:3306/phoneshopsystem", "root", dbLogin.db());
    			stm = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    			rset = stm.executeQuery("SELECT phoneID FROM `phones`");
     
    			while(rset.next()){
    				model.addElement(rset.getInt(1));
    			}
     
    			con.close();
     
    		}catch(SQLException sql){
    			JOptionPane.showMessageDialog(null, "SQL Exception: "+sql.getMessage());
    		}
     
    		return model;
    	}

    The code works fine initially, but when i click on the refresh button, i get this in the ComboBox: javax.swing.DefaultComboBoxModel@1a38598 instead of the supposed values. Is that an exception? or something else?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: javax.swing.DefaultComboBoxModel@1a38598

    javax.swing.DefaultComboBoxModel@1a38598
    That looks like the String returned by a class's default toString() method. If you use a reference to an object where the compiler expects a String then the compiler generates a call to that object's toString() method which will return that String if the class has not overridden the toString() method.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Apr 2011
    Location
    Niperia
    Posts
    30
    My Mood
    Amazed
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: javax.swing.DefaultComboBoxModel@1a38598

    Does it mean am supposed to convert it to a string using the toString() method of String class before outputting it?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: javax.swing.DefaultComboBoxModel@1a38598

    I'm not sure what the code does to get that String. If you want to get the contents of an object, you need to call some of its methods. The String you are seeing is returned by the object's toString() method and is obviously not what you want to get. Read the API doc to see what methods are available to get the data from the object.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Does javax.swing.JToggleButton even lift ??
    By startas in forum AWT / Java Swing
    Replies: 6
    Last Post: September 8th, 2013, 11:49 AM
  2. trouble with selectAll() method of javax.swing.JTextField
    By Daddyspike in forum AWT / Java Swing
    Replies: 0
    Last Post: April 27th, 2013, 05:40 PM
  3. What's the difference between "import.javax.swing*" and JFrame inheritance
    By Johnny Bravo in forum Object Oriented Programming
    Replies: 5
    Last Post: August 14th, 2012, 09:28 AM
  4. Replies: 3
    Last Post: June 11th, 2011, 02:40 PM
  5. [SOLVED] [Problem] imports javax.swing problem
    By Brollie in forum AWT / Java Swing
    Replies: 8
    Last Post: July 5th, 2009, 07:59 AM