Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JTable Enhancements.

Posted on 2000-05-16
5
Medium Priority
?
503 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn different types of Android Layout and some basics of an Android App.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

636 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