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 9 of 9

Thread: 1 vertical scroll bar fro 2 jtextareas

  1. #1
    Member
    Join Date
    Oct 2010
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 1 vertical scroll bar fro 2 jtextareas

    Hi Guys,

    I have two jtext area boxes, is it possible to have 1 vertical scroll bar to scroll both of them at the same time. I have looked over the net and cant really find anything , can you guys help me.



    Thankyou


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,159
    My Mood
    Hungover
    Thanks
    141
    Thanked 595 Times in 510 Posts

    Default Re: 1 vertical scroll bar fro 2 jtextareas

    There are several ways to do this. You could just set put one of the JTextAreas in the JScrollPane, add a listener to the JScrollPane or the vertical scroll bar, and call scrollRectToVisible() when that listener fires. Or you put a JScrollPane on both of them, then have those JScrollPanes share either models or vertical scroll bars.

    Try googling "java fixed JTable column" or "fixedtable", something like that. Let me know if you're still having issues after that.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Oct 2010
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: 1 vertical scroll bar fro 2 jtextareas

    right i have jtextarea2 in a jScrollPane and jtextarea1 on its own, however i cant work out how to get the jtextarea1 to "scrollRectToVisible() ". Currently when jtextarea1 gets filled up with text and more is added the box length is extended

  4. #4
    Member
    Join Date
    Oct 2010
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: 1 vertical scroll bar fro 2 jtextareas

    right ignore what i said, I have decided to use a Table instead of two text areas, it will work out better

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,159
    My Mood
    Hungover
    Thanks
    141
    Thanked 595 Times in 510 Posts

    Default Re: 1 vertical scroll bar fro 2 jtextareas

    Heh, okay. Note that you can actually use JTextAreas as the renderer for the cells of a JTable.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Member
    Join Date
    Oct 2010
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: 1 vertical scroll bar fro 2 jtextareas

    my knowledge at java is rather baisc,

    Im using netbeans to create the table (GUI builder) and what i have done is create a table(3 cols, 2 rows) and now what i am trying to do is have a button you can press and it will add a blank row allowing data to be put in it, however im getting no where.

    Ive read that a simple command like jTable1.addRow(new Object[]{null,null,null}); would do the job, however i think because im using netbeans to create the table im getting problems it does not like the addRow bit saying it cannont find the symbol

    I also think this may be casuing the prob two

    " jTable1.setModel(new javax.swing.table.DefaultTableModel(
    new Object [][] { "
    Last edited by fortune2k; March 4th, 2011 at 12:27 PM.

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,159
    My Mood
    Hungover
    Thanks
    141
    Thanked 595 Times in 510 Posts

    Default Re: 1 vertical scroll bar fro 2 jtextareas

    If you want an honest answer, I urge you to ditch the GUI builder immediately.

    Without seeing the actual code (in SSCCE form, which means no GUI-builder code) and the actual Exception and stack trace, I can't really comment on what you're doing wrong. But the line you posted is definitely incorrect syntax- at the very least, you need to close the opening parenthesis of the constructor for DefaultTableModel.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    Member
    Join Date
    Oct 2010
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: 1 vertical scroll bar fro 2 jtextareas

    lol, right ive gone back to the original idea because its simple and i can kinda understand it at the moment

    EDIT: I have given up and left the project I think im going to get someone to make the program for me
    Last edited by fortune2k; March 4th, 2011 at 01:00 PM.

  9. #9
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,159
    My Mood
    Hungover
    Thanks
    141
    Thanked 595 Times in 510 Posts

    Default Re: 1 vertical scroll bar fro 2 jtextareas

    That's a shame. You were probably really close to the solution. If you post an SSCCE, I'd love to help you through it.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. [SOLVED] Scroll down in JOptionPane and window problems.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 60
    Last Post: June 16th, 2010, 12:04 PM
  2. Replies: 1
    Last Post: May 21st, 2009, 03:41 AM