Results 1 to 9 of 9
  1. #1
    JetsYanks is offline Member
    Join Date
    May 2008
    Posts
    1
    Rep Power
    0

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

    Java 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);
            
            }
    }

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    What about JScrollPane? have you try to use it for the JList?
    freedom exists in the world of ideas

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  4. #4
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    yah...

    @ OP, have a look at the getContentPane().add(something)...
    only jlist and jtext are added...

    You can bring them at the bottom.
    and add the panels like what you did in jlist
    freedom exists in the world of ideas

  5. #5
    Belete is offline Member
    Join Date
    Dec 2009
    Location
    AddisAbaba
    Posts
    10
    Rep Power
    0

    Default

    Hi can some body help me out with this, i was trying to display a directory list from a folder toa jlist using the following code
    String st;
    while( (st.length)!=-1)
    {
    fileName=in.readUTF();
    String data[] = {fileName};
    jList1=new JList(data);
    }
    but it only displays one file, how could i correct this please help me.

  6. #6
    Belete is offline Member
    Join Date
    Dec 2009
    Location
    AddisAbaba
    Posts
    10
    Rep Power
    0

    Default

    Hi can some body help me out with this, i was trying to display a directory list from a folder toa jlist using the following code
    String st;
    while( (st.length)!=-1)
    {
    fileName=in.readUTF();
    String data[] = {fileName};
    jList1=new JList(data);
    }
    but it only displays one file, how could i correct this please help me.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by Belete View Post
    Hi can some body help me out with this,...
    Belete, rather than hijack an old thread, please start a new thread for your question. Thanks for your cooperation.

  8. #8
    Belete is offline Member
    Join Date
    Dec 2009
    Location
    AddisAbaba
    Posts
    10
    Rep Power
    0

    Default

    Ok thanks i will

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Again, thanks. Do so, and I can almost guarantee swift help for you. :)

Similar Threads

  1. JList problem
    By zizou147 in forum Advanced Java
    Replies: 1
    Last Post: 04-17-2008, 08:50 AM
  2. Problems with JPanels and displaying
    By Mastergeek666 in forum AWT / Swing
    Replies: 1
    Last Post: 01-19-2008, 12:32 AM
  3. Can't synchronize multiple JPanels in a JFrame
    By vassil_zorev in forum AWT / Swing
    Replies: 0
    Last Post: 12-30-2007, 04:22 PM
  4. How to add Images to JPanels?
    By Soda in forum New To Java
    Replies: 3
    Last Post: 12-08-2007, 05:54 PM
  5. Help with JList
    By Albert in forum NetBeans
    Replies: 1
    Last Post: 07-13-2007, 03:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •