Results 1 to 10 of 10
  1. #1
    matpj is offline Member
    Join Date
    Sep 2008
    Posts
    42
    Rep Power
    0

    Default why isn't my combobox appearing on my frame?

    Hi all,
    I have the following (simple) code so far for my JFrame.
    Java Code:
    import javax.swing.*;
    import java.awt.FlowLayout;
     
     
    /**
     *
     * @author mjohnson
     */
    class ProjectConversions extends JFrame{
     
        public ProjectConversions(){
     
            setTitle("PS-Clarity Project Conversions Interface");
            
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setSize(300,300);
            
            JComboBox entity = new JComboBox();
     
            EntityProvider comboFill = new EntityProvider();
            //Fill JComboBox with values retrieved from EntityProvider Class
            for(String name :comboFill.fileArray){
                  entity.add(name, this);
            }
            
            entity.setVisible(true); //set combobox to visible
     
            setVisible(true);  //set frame to visible
        }
     
    }

    Java Code:
    I am using a different class with a main method calling this frame:
    public class ProjectConverstionMain {
     
        public static void main(String args[]){
            new ProjectConversions();
        }
     
    }


    The combo box is being populated from an ArrayList in another class but it is not visible when I run the main method.
    I can see the JFrame with the title I have set - but no ComboBox..

    any ideas?

    thanks in advance,
    Matt

  2. #2
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    I dont think you have added the combo box to frame.

  3. #3
    matpj is offline Member
    Join Date
    Sep 2008
    Posts
    42
    Rep Power
    0

    Default

    I don't suppose you could show me how to do that?
    I have given a new instance of JComboBox the name 'entity'
    how would I then add entity to the frame?

  4. #4
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    public ProjectConversions(){

    setTitle("PS-Clarity Project Conversions Interface");

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(300,300);

    JComboBox entity = new JComboBox();

    EntityProvider comboFill = new EntityProvider();
    //Fill JComboBox with values retrieved from EntityProvider Class
    for(String name :comboFill.fileArray){
    entity.add(name, this);
    }

    entity.setVisible(true); //set combobox to visible
    add(entity); // if your version is jdk1.5 or above
    //getContentPane().add(entity); for lower versions
    setVisible(true); //set frame to visible
    }

  5. #5
    matpj is offline Member
    Join Date
    Sep 2008
    Posts
    42
    Rep Power
    0

    Default

    Thanks for that.
    only trouble I have now is I cant seem to set the size of it, have tried entity.setsize(50,100); but it doesn't make a difference.
    oh, and it is not showing any contents that I have set using the for loop!!

  6. #6
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Don't double post

    Dude, don't double post... it's really a good way to anger people who are trying to help you. Why? Because you could have gotten the answer a long time ago on a another forum and people on this forum are still trying to help you.
    New To Java - Why isn't my combobox being displayed on my JFrame?
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  7. #7
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    Not very sure about setSize, I suggest set the layout of JFrame to null and use setBounds method with the components in your case that entity object
    e.g. entity.setBounds(xCoordinate,yCoordinate,width,hei ght)

    Now as far as items not appearing in the combo box, what does comboFill.fileArray is returning? Use System.out to print its contents inside the loop and make sure you are getting the values.

  8. #8
    matpj is offline Member
    Join Date
    Sep 2008
    Posts
    42
    Rep Power
    0

    Default

    Quote Originally Posted by CJSLMAN View Post
    Dude, don't double post... it's really a good way to anger people who are trying to help you. Why? Because you could have gotten the answer a long time ago on a another forum and people on this forum are still trying to help you.
    New To Java - Why isn't my combobox being displayed on my JFrame?
    Chris,
    I see what you are saying but the only reason I posted twice was to give me more of a chance to get a rapid answer - as the project is time critical.

    its also interesting to see different ways to acheive the same thing - as being a learner it will allow me to adopt the more understandable route.

    apologies if this angered you.

  9. #9
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    Double posting doesn't get you answers faster. If you are looking for different ways to do something (and I'm not convinced that that's a valid reason for double posting), then explain in your post that you have also posted in another forum (provide the link) and the reason why. That way, everybody's on the level.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  10. #10
    matpj is offline Member
    Join Date
    Sep 2008
    Posts
    42
    Rep Power
    0

    Default

    thanks,
    I will bare that in mind for the future.
    I have to disagree about response times.
    some forums seem to be more active Stateside than in the UK.
    I have found some questions on Sun are answered very quickly, where some on Java-Forums go unanswered.
    I suppose it's probably just luck of the draw.

    its not that I am looking for different ways to skin a cat, but often you find that different people have different ways of doing things.
    either way, we're getting away from my purpose of this exercise anyway.

    i'm just after a bit of help to understand what the heck I am doing! :-)
    I am not picking things up as quickly as I would have hoped with something that I thought would be SO easy to acheive...

Similar Threads

  1. ComboBox with CheckBoxes
    By heba.farouk in forum AWT / Swing
    Replies: 14
    Last Post: 06-09-2010, 11:03 AM
  2. XTerm window appearing in full screen swing app
    By clarose in forum AWT / Swing
    Replies: 1
    Last Post: 11-17-2008, 10:56 PM
  3. combobox
    By chandu.v in forum New To Java
    Replies: 2
    Last Post: 07-02-2008, 08:36 PM
  4. tomcat resource bundle tab not appearing??
    By freddieMaize in forum NetBeans
    Replies: 2
    Last Post: 05-25-2008, 09:15 AM
  5. Log messages are not appearing in my log file
    By indu_raj in forum Java Servlet
    Replies: 1
    Last Post: 08-08-2007, 11:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •