2011-11-25 2 views
0

내가 넷빈즈에의 JList을 그리고 난이 코드를 작성했지만 코드 내 JList의만들기 넷빈즈 프레임에서의 JList

/** Creates new form Toetsenbordd */ 
    public Toetsenbordd() { 
     initComponents(); 
     initCustomComponents(); 
    } 

    private void initCustomComponents(){ 
    JList Lijstje; 
    JScrollPane Lijst; 

     String filename[]= {"Ard ","Astronauts", 
      "Behind the Scene Movie credits","DNA Research -- the Human Genome Project", 
      "Extract from The Adventures of Pinocchio","History of Photography", 
      "Hubble Space Telescope","Legends of Abraham Lincoln","Netiquette", 
      "Observations of the Father of Computing (1791 - 1871)","Rules of Baseball (from 1889)", 
      "Speeding up the strategy process","Stinging Insects","The Eight Tools for Creating New Values", 
      "The Life of Calamity Jane","The Little Match Girl (adapted)","The Tail of Peter Rabbit", 
      "Thoughts of Banjamin Franklin","What is the Cast","Yosemite National Park" 
      }; 
     { 

      Lijstje = new JList(filename); 
      Lijstje.setFont(new Font("Arial",Font.PLAIN,15)); 
     Lijst =new JScrollPane(Lijstje); 
     Lijst.setSize(410,200); 
     Lijst.setLocation(70,75); 
     Lijstje.setVisibleRowCount(6); 
     Lijstje.setSelectedIndex(0); 
     Lijstje.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 
     //seting the border for filescroll 
     Lijst.setBorder(BorderFactory.createTitledBorder("CHOOSE TEST")); 

     add(Lijst); 

    }  



    } 

그것은 내 selfmade JFrame의의 한가운데에 서 있지 사라져 :

enter image description here

하지만 난이 원하는 곳이 항목 1,2,3 모든

+0

귀하의 질문에 나를 위해 명확하지 않다 레이아웃 yor 두 JList하는 방법에 대해 얘기하고있다 ??? – mKorbel

+0

Toetsenbordd 란 무엇입니까? 어떤 클래스가 확장합니까 –

+0

중간에있는 Jlist 제목이 Jlist에 속해 있지 않은 사람은 항목 1은 예를 들어 곤충을 찌르며 toetsenbordd는 내 Jframe의 이름입니다 –

답변

2

먼저 대문자와 변수 이름을 시작하지 마십시오,이 난을 말한다 s를 Java naming conventions에 대해

setLocation은 코드에 Lijst에 절대 위치를 지정하려는 것을 의미합니다. 이는 LayoutManager를 사용하지 않을 때만 가능합니다 (this tutorial 참조).

setLayout(null) 

그러나이 null 레이아웃 매니저와 함께 이동하지 않는 것이 좋습니다, 당신은 정말 list

에서 하나를 사용하는 것이 좋습니다 : BorderLayout이 기본이기 때문에 명시 적으로 null에 레이아웃 매니저를 설정해야합니다 것을해야 할 일