JScrollPane with JTextArea


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: JScrollPane with JTextArea

  1. #1
    Join Date
    Nov 2005
    Posts
    4

    JScrollPane with JTextArea

    Hi,

    I was wondering if anyone has a simple code of how to use JTextArea with JScrollPane? my results are displayed without any problem if the JScrollPane is not used.The code fetches the data from database and then displays it. This is a part of my code with JScrollPane in it..

    public class Applet1 extends JApplet {

    private JButton DbConnect = new JButton();
    private JTextArea empValues = new JTextArea();
    JScrollPane ScrollempValues=new JScrollPane(empValues);

    //empvalues.setContentPane(ScrollempValues);

    private Connection con;
    private JLabel jLabel1 = new JLabel();
    //ScrollempValues.getHorizontalScrollBar();


    public Applet1() {
    }

    public void init() {
    try {
    jbInit();
    } catch(Exception e) {
    e.printStackTrace();
    }
    }
    private void jbInit() throws Exception
    {
    this.getContentPane().setLayout(null);
    DbConnect.setText("Click to Connect to DB");
    DbConnect.setBounds(new Rectangle(90, 550, 175, 40));
    DbConnect.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    connectToDB(e);
    }
    });
    empValues.setBounds(new Rectangle(40, 50, 500, 500));
    jLabel1.setText("Emp Records :");
    jLabel1.setBounds(new Rectangle(45, 20, 155, 20));
    this.getContentPane().add(jLabel1, null);
    this.getContentPane().add(empValues, null);
    // getContentPane().add(ScrollempValues, BorderLayout.CENTER);

    JScrollPane ScrollempValues = new JScrollPane( empValues );
    this.getContentPane().add(ScrollempValues, BorderLayout.CENTER);
    this.getContentPane().add(DbConnect, null);


    Thanks,

    nits.

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Use this code for putting anything (like a JTextArea) into a JScrollPane:

    theScrollPane.getViewport().add(theTextArea);

    and all will be fine. You may want to alter some textarea linewrapping/wordwrapping too.
    eschew obfuscation

Similar Threads

  1. Painting in a threaded JScrollPane
    By pgillet in forum Java
    Replies: 3
    Last Post: 10-11-2005, 04:28 AM
  2. Replies: 0
    Last Post: 07-11-2005, 09:41 PM
  3. JPanel paintComponent inside JScrollPane
    By vu_tech in forum Java
    Replies: 1
    Last Post: 04-08-2005, 10:36 AM
  4. JTextArea
    By bilinmiyo in forum Java
    Replies: 1
    Last Post: 03-04-2005, 06:57 AM
  5. ShowMessageDialog from JTextArea
    By Huiyuanm in forum Java
    Replies: 1
    Last Post: 03-22-2000, 08:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center