Results 1 to 3 of 3
  1. #1
    adonos is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default JTable vs JTextArea scrolling text question

    Hi all, I am a new Java programmer trying to learn Java for work. I am trying to decide which component to use to create a window that will display scrolling text from an actionlistener. Every time the listener receives a new event, I want to display the time it was received and the event at the top of the window and to have the older events scroll down the window, and eventually off. I want to be able to resize columns in the window, for example giving the "time" field more space. I also want to keep cpu usage low and I feel like it would be intensive if I created a JTable and manually pushed the old entries down a row each time a new entry comes in. I think my preference would be to use a JTable, but I am also unsure of how to dynamically create new rows until I have like 1000 events, and then start pushing the oldest events off.

    I am just looking for some opinions on if I would be better off using a JTable or a JTextArea.

    I apologize if this is a stupid question, or if I am missing something obvious. Thank you in advance for your help.

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

    Default

    First off, welcome to the forum!

    Next as to your question, I'd push for using a JTable, and for this JTable's model, I'd use a class that extends DefaultTableModel (or if you're brave, AbstractTableModel). By doing this, you should make adding and removing rows relatively easy.

    Much luck, and please let us know how things progress.

  3. #3
    adonos is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default

    Thank you Fubarable!

    For my current purposes, I think a fairly simple table that I can add rows to easily would suffice, but I want to try to get used to proper Java techniques. So, I made my own table class which extends JTable, instantiates a DefaultTableModel, a JTable and 3 myTableColumns, which I think instantiates a DefaultTableColumnModel and 2 ColumnRenderers. Is this a good way to go? I do not know if I should be instantiating a JTable in a class that I am also extending JTable with.

    Also, I want to make this table take up the entire window. Right now I have to manually set the window size, if I do not specify a size, it seems to default to 0,0 and I get a very small window, and if I expand or shrink the window, the table does not resize with it, Ill either have a large empty area around the table or just be able to see the top middle section of the table. Any advice on what methods to look at? Right now I am putting the table in a JScrollPane, putting the JScrollPane into a JPanel and my main class extends JFrame.

    Thank you again in advance!

Similar Threads

  1. How to add JTextArea in JTable - Swing
    By phungho2000 in forum AWT / Swing
    Replies: 5
    Last Post: 12-17-2008, 09:18 PM
  2. How to display scrolling text and image on a JFrame
    By Abhi_vk in forum AWT / Swing
    Replies: 1
    Last Post: 06-20-2008, 10:19 PM
  3. Need Help showing text in JTextArea
    By GuyFawkes in forum AWT / Swing
    Replies: 3
    Last Post: 05-05-2008, 09:19 AM
  4. JTextArea - text align
    By bradder in forum AWT / Swing
    Replies: 1
    Last Post: 11-29-2007, 07:08 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
  •