?
Solved

JTable Enhancements.

Posted on 2000-05-16
5
Medium Priority
?
502 Views
Last Modified: 2013-11-23
Hello Every Body!,

I am doing programming in Swing - Applet.  In this

  1. I need to know how to i maintain the real time data in JTable.

  2. How to i do coding for gui enhancement like font, color -background, foreground for particular cell.
  3. how to i do sorting with multiple columns.

  4. for this which tablemodel i have to inherit.

 Can any one help.

Regards..

s.pushparaj


   


0
Comment
Question by:santham
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Expert Comment

by:kylar
ID: 2815341
1.What do you mean by real time data? if you update the model of a table then call revalidate() then it will update with the new data.

2. GUI Enhancement would be done by playing with TableCellRenderers. if you want to change the background, foreground etc.. you could either get the default renderer and change it, or implement your own class that has the foreground and background set to whatever colours you want.
3. this is extremely difficult. you would have to make your own class of tablesorter, which goes through and sorts by one column, and then the second, creates a new TableModel then attaches the new Model to your JTable, and finally calls revalidate() and/or repaint().
4. Well, this is probably going to be an extention of DefaultTableModel, or possibly AbstractTableModel, depending on how much functionality you want and need to customize. it doesn't really matter which one you inherit from, you could write your own as long as it implements the TableModel interface.

Hope this helps,
Kylar
0
 

Expert Comment

by:anilbathula
ID: 2815977
For background and foreground colors use TableCellRenderers
   
  1. Set background and foreground color same for all the cells then use getDefaultCellRenderer(Class columnClass) gives the TableCellRenderers Class then cast it to DefaultTableCellRenderer . For DefaultTableCellRenderers have setBackground(Color) and setForeground(Color) using these method set the colors.
 
2. For particular cell with particular color then use getCellRenderer(int row,int column) then use cast it to DefaultTableCellRenderer and use the same methods.

Some sorting examples: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#sorting
0
 
LVL 7

Accepted Solution

by:
vladi21 earned 225 total points
ID: 2816393
You can look excelent examples with sources at:

http://www2.gol.com/users/tame/swing/examples/SwingExamples.html 

Also look:

http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

http://manning.spindoczine.com/sbe/files/uts2/Chapter18html/Chapter18.htm 
http://users.vnet.net/wwake/swing/faq.html#table
http://www.codeguru.com/java/Swing/JTable/index.shtml
http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/ 
   
---
How update JTable after I modify the data?
TableModel model=table.getModel();
if (model instanceof AbstractTableModel){
((AbstractTableModel)model).fireTableDataChanged();
}

or implemant your TableModel explicitly.

DefaultTableModel model = new DefaultTableModel();
JTable table = new JTable(model);

--
JTable highlight selected cells
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=10219262 

----
I have JTable in a GUI and a button to save the data in the table to a database. The JTable's view and model are separate. When I do a save, the data in the last cell which I edited is lost.

Only if I change the focus to a different cell or if I press ENTER key, it fires an event to update the cell (i.e. it calls the "setValue" method in the data model). Without this, how can I fire an event to update the data in the cell.

if (isEditing()) myDefaultCellEditor.stopCellEditing();
or
if (isEditing()) getDefaultEditor(String.class).stopCellEditing();

---
How can I clear data entered into a JTable?
http://developer.java.sun.com/developer/qow/archive/23/index.html
http://developer.java.sun.com/developer/qow/archive/archive.html

http://java.sun.com/products/jdk/1.3/docs/guide/swing/JTableChanges.html
0
 

Author Comment

by:santham
ID: 2982930
Answer accepted
0
 

Author Comment

by:santham
ID: 2982931
Thanks valdi,

very good explanation for sorting and cell renderering.    



thanks...


s.p.raj
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month9 days, 20 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question