View Single Post
  #1 (permalink)  
Old 05-12-2008, 04:25 AM
JetsYanks JetsYanks is offline
Member
 
Join Date: May 2008
Posts: 1
JetsYanks is on a distinguished road
JList and JPanels
Hey everyone, Ive recently started working with Java and have a basic grasp to it, but I hit a problem. When I enter a JList into a JPanel, the list will show up, but any other JPanels I add will not show up(when I run void-main option in BlueJ), and Im not sure as to what Im doing wrong because I'm having no Compiling Issues.

Heres an example of my code-

Code:
import java.awt.*; import javax.swing.*; import javax.swing.event.*; public class Test extends JFrame { private String[] stringNames = {"Test1", "Test2", "Test3", "Test4", "Test5", "Test6", "Test7", "Test8", "Test9", "Test10", "Test11"}; private JList jlist = new JList(stringNames); private JTextField jtext = new JTextField("--Welcome--"); public static void main(String[] args) { Test frame = new Test(); frame.setSize(650, 550); frame.setTitle("Welcome to Java"); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } public Test() { Container container = getContentPane(); getContentPane().setLayout(new FlowLayout()); getContentPane().add(jlist); getContentPane().add(jtext); JList jlist = new JList(stringNames); JPanel p1 = new JPanel(); p1.add(jlist); JPanel p2 = new JPanel(); JPanel p3 = new JPanel(); p2.add(jtext); p2.add(p1, BorderLayout.WEST); p3.add(p2, BorderLayout.EAST); } }
Reply With Quote
Sponsored Links