Results 1 to 3 of 3
- 05-23-2010, 08:09 PM #1
Member
- Join Date
- May 2010
- Posts
- 2
- Rep Power
- 0
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.
-
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.
- 05-24-2010, 08:15 PM #3
Member
- Join Date
- May 2010
- Posts
- 2
- Rep Power
- 0
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
-
How to add JTextArea in JTable - Swing
By phungho2000 in forum AWT / SwingReplies: 5Last Post: 12-17-2008, 09:18 PM -
How to display scrolling text and image on a JFrame
By Abhi_vk in forum AWT / SwingReplies: 1Last Post: 06-20-2008, 10:19 PM -
Need Help showing text in JTextArea
By GuyFawkes in forum AWT / SwingReplies: 3Last Post: 05-05-2008, 09:19 AM -
JTextArea - text align
By bradder in forum AWT / SwingReplies: 1Last Post: 11-29-2007, 07:08 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks