Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Swing JList

Tags:

java

swing

jlist

I am using a JList in Java Swing, but when my Dialog opens, the List isn't shown.

private JList getJList() {
  if (mylist == null) {
   mylist = new JList();
   mylist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   mylist.setSize(new Dimension(154, 106));
   model.addElement("test");
   model.addElement("zwei");
   mylist.setVisible(true);

  }
  return mylist;
 }

The list is defined:

private JPanel getJContentPane() {
  if (jContentPane == null) {
   jContentPane = new JPanel();
   jContentPane.setLayout(new BorderLayout());
   jContentPane.add(getJList(), BorderLayout.CENTER);

  }
  return jContentPane;
 }

It's a JContentPane (/Panel)

public fensterdrei(Frame owner) {
  super(owner);
  initialize();
  }

the code calling getJContentPane():

private void initialize() {
      this.setSize(300, 200); 
      this.setContentPane(getJContentPane()); 
      this.setTitle("Auswahl"); 
} 
like image 441
Tyzak Avatar asked Jan 25 '10 15:01

Tyzak


1 Answers

I can't find where you are setting the model of the JList?

Something like

mylist = new JList();    
mylist.setModel(model);

Please have a look at the Code Conventions for the Java Programming Language

FensterDreiinstead of fensterdrei
myListinstead of mylist

like image 68
user85421 Avatar answered Nov 04 '22 21:11

user85421