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 7 of 7

Thread: Comboboxes in JFrame

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Comboboxes in JFrame

    Hi guys am trying to add two comboboxes in a frame. but am getting the problem in that. Kindly help me. i have tried many things but couldn't rectify the problem.


    public class IndexPerformanceView extends JFrame implements ActionListener {
    private static final long serialVersionUID = 1L;
    private IndexPerformanceControl model;
    private Box filter;
    private JComboBox xchg;
    private JComboBox chgtype;
    private JFrame jframe;
    private Object ContentPane;
    public static int selectedindex;
    public IndexPerformanceView() {

    this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE );
    this.setIconImage(Images.LoadImage("icon.gif"));
    model = new IndexPerformanceControl();
    this.getContentPane().add(model, BorderLayout.SOUTH);
    xchg = new JComboBox(new String[] { "NSE" });
    xchg.addActionListener(this);
    this.getContentPane().add(xchg, BorderLayout.CENTER);
    chgtype = new JComboBox(new String[] { "Change%", "Change" });
    chgtype.addActionListener(this);
    this.getContentPane().add(chgtype, BorderLayout.EAST);
    this.pack();
    this.setTitle("IDX Performance");
    this.setBounds(100, 100, 600, 480);
    }

    I am trying to add two comboboxes xchg and chgtype at the top of the frame. but when i do it am getting the problem. I will send you the screenshot..
    Attached Images Attached Images


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,606
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: Comboboxes in JFrame

    What is the problem? What do you expect to happen? What is happening instead?

    I recommend you read up on layouts. A google search of "java layouts" should get you on the right track.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Comboboxes in JFrame

    Quote Originally Posted by KevinWorkman View Post
    What is the problem? What do you expect to happen? What is happening instead?

    I recommend you read up on layouts. A google search of "java layouts" should get you on the right track.

    @KevinWorkman. I need both the combo boxes in one panel side by side. i.e i need the xchg combo and chgtype combo side by side instead of the entire panel.i have kept the screenshot about my error..

  4. #4
    Junior Member
    Join Date
    Mar 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Comboboxes in JFrame

    @KevinWorkman i couldnt get two comboxes in a single panel.

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,606
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: Comboboxes in JFrame

    Okay, and did you research layouts at all?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Junior Member
    Join Date
    Mar 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Comboboxes in JFrame

    Quote Originally Posted by KevinWorkman View Post
    Okay, and did you research layouts at all?

    I have done it but couldnt get this problem rectified!! i tried borderlayout,gridlayout but i don know how to get two comboboxes in a jframe!!

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,606
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: Comboboxes in JFrame

    Either one of those layouts should work, as should several otehrs. Take another look at the tutorials, and post an SSCCE if you're still stuck.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. using objects from one jFrame on a different jFrame
    By Taskeen in forum AWT / Java Swing
    Replies: 3
    Last Post: September 14th, 2011, 09:51 AM
  2. connecting jframe to another jframe
    By ajtambalo in forum Member Introductions
    Replies: 2
    Last Post: May 11th, 2011, 12:24 PM
  3. Pop-out box using a JFrame.
    By ShaunB in forum Java Theory & Questions
    Replies: 6
    Last Post: April 28th, 2011, 01:03 PM
  4. JFrame
    By M3ss1ah in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 23rd, 2011, 04:24 PM
  5. JFrame help
    By Uden in forum AWT / Java Swing
    Replies: 0
    Last Post: August 14th, 2009, 02:37 PM