Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: JScrollPane not showing up

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    40
    My Mood
    Sneaky
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default JScrollPane not showing up

    I'm trying to write a GUI that has 2 JPanels, the left panel with an image and JLabel below it, and the right one with a scrollable JTextArea. For whatever reason the JTextArea isn't showing up.

     import javax.swing.*;
    import java.awt.*;
     
    public class TextAreaDemo extends JFrame 
    {
      private JPanel p1, p2;
      private ImageIcon javaIcon;
      private JLabel jlblIcon;
      private JTextArea jtxtDetails;
      private JScrollPane scrollPane;
     
      public TextAreaDemo() 
      {
        p1 = new JPanel();
    	 p1.setLayout(new GridLayout(2, 1));
    	 p1.add(new JLabel(javaIcon = new ImageIcon("image\\java.jpg")));
    	 p1.add(jlblIcon = new JLabel("An Icon"));
    	 jlblIcon.setFont(new Font("Helvetica", Font.BOLD, 20));
     
    	 add(p1, BorderLayout.WEST);
     
    	 p2 = new JPanel();
    	 p2.add(jtxtDetails = new JTextArea("Java uses the javax.swing.ImageIcon class to represent an icon. An icon is a fixed-   size picture; typically it is small and used to decorate.", 100, 100));
    	 jtxtDetails.setLineWrap(true);
    	 jtxtDetails.setWrapStyleWord(true);
    	 scrollPane = new JScrollPane(jtxtDetails);
     
    	 add(p2, BorderLayout.EAST);
      }
     
      public static void main(String[] args) 
      {
        TextAreaDemo frame = new TextAreaDemo();
        frame.setTitle("TextAreaDemo");
        frame.pack();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);	 
        frame.setVisible(true);
      }
    }


  2. #2
    Member
    Join Date
    Jan 2013
    Posts
    34
    My Mood
    Busy
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default Re: JScrollPane not showing up

    Aha! That's it, you forgot to add the scrollPane. Do this by doing
    add(scrollPane);

    I hope I helped!

  3. The Following User Says Thank You to vividMario52 For This Useful Post:

    mwardjava92 (February 27th, 2013)

  4. #3
    Member
    Join Date
    Oct 2011
    Posts
    40
    My Mood
    Sneaky
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Re: JScrollPane not showing up

    Thank you! I've been looking at it for hours with no success!

Similar Threads

  1. JScrollPane not showing scroll bars
    By Stx in forum AWT / Java Swing
    Replies: 9
    Last Post: July 5th, 2012, 11:37 AM
  2. JScrollPane Difficulty. Help Please
    By AceApple in forum AWT / Java Swing
    Replies: 2
    Last Post: June 24th, 2012, 05:30 PM
  3. Replies: 3
    Last Post: March 6th, 2012, 03:50 AM
  4. [SOLVED] need help, Problem in JScrollPane
    By sny in forum AWT / Java Swing
    Replies: 5
    Last Post: March 15th, 2010, 07:16 AM
  5. JScrollPane
    By MysticDeath in forum AWT / Java Swing
    Replies: 1
    Last Post: February 17th, 2010, 10:21 PM