Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JComboBox  RSS feed

 
shakila
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have this JComboBox that displays just 1 item at a time although the Vector that initializes it has hundreds of elements. When I checked with the .getMaximumRowCount() function return value it is 8. Is there a way to set the number of rows for a JComboBox? Thanks.
Shakila
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi shakila,
JComboBox component is meant to enable the user to select only one item at a time.if u want to show more than one item. u should use JList.
regards
deekasha
 
shakila
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for answering but I don't want the user to select more than one item, but I want to be able to see more than 1 of the items. I'm not sure why this happens, but I have a text area right below this JComboBox in my GridLayout, this may be causing this to happen.
Shakila
 
TransZamboni
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may be a long shot but...Is the text area a heavyweight? If so then it is painting on top of your combo box.
 
shakila
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Nope all the components on the frame are light weight! (JTextFields and JTextAreas). I even tried doing jcombobox.setMaximumRowCount(int) and it didn't work!
Shakila
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shakila,
firtly i'm sorry to misunderstand ur problem in my earlier post.now regarding ur problem i wrote two small program. and the conclusion i came to is that may be u r mixing awt component with swing component.(e.g. u r adding swing components on a awt Frame instead of JFrame.).
just run these two programs
------------------------------------------------------
this program will give same problem as u r facing
import javax.swing.*;
import java.util.*;
import java.awt.*;
class Combo
{
public static void main(String h[])
{
Frame f = new Frame();
Vector v = new Vector();
v.add("Hi");
v.add("Hello");
v.add("Happy");
JComboBox jbx = new JComboBox(v);
JTextField jfld = new JTextField("JTextField");
f.setLayout(null);
jbx.setBounds(50,50,50,25);
jfld.setBounds(50,80,50,25);
f.add(jbx);
f.add(jfld);
f.setSize(300,300);
f.setVisible(true);
}
}
------------------------------------------------------
==============================================================
this will run perfectly since i've replced the frame of first program with JFrame
import javax.swing.*;
import java.util.*;

class Combo
{
public static void main(String h[])
{
JFrame f = new JFrame();
Vector v = new Vector();
v.add("Hi");
v.add("Hello");
v.add("Happy");
JComboBox jbx = new JComboBox(v);
JTextField jfld = new JTextField("JTextField");
f.getContentPane().setLayout(null);
jbx.setBounds(50,50,50,25);
jfld.setBounds(50,80,50,25);
f.getContentPane().add(jbx);
f.getContentPane().add(jfld);
f.setSize(300,300);
f.setVisible(true);
}
}
-----------------------------------------------------

so just make sure u r not mixing awt and swing components.
one more thing if u solve this problem then do let us know.
coz it seems to be interesting.
regards
deekasha
 
shakila
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for all your help. I know why this happens. I had assigned the first element of the Vector to be a empty string (""). This was why that was happening. When I changed that into a string it showed more than one item on being opened.
Shakila
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!