JTable Selection

I am using JTable to load messages, fetching from server.

I want

1) Table should not allow any editing.

2) click on any cell should select the row

3) mouse Double click implementation

4) setting background for the particular rows.

Thank you,

please reply

[304 byte] By [JTable_need_infoa] at [2007-11-26 21:59:18]
# 1

1) read the tutorial I gave you in your other posting. (basically you override the isCellEditable() method of JTable or the TableModel

2) this is the default behaviour

3) what does this mean

4) again not a lot of information. Is this based of some data contained in the row. If so then search the forum for my TablePrepareRenderer example. If this done randomly, then search the forum for my TableColor example.

camickra at 2007-7-10 3:58:10 > top of Java-index,Desktop,Core GUI APIs...
# 2

I am preparing a system for my project and the system is "Email client" which get the messages from server and allows the operations on it.

So to show the messages in the tabular form I am using JTable.

SO I think u will be able to understand my need.

ref to 1) thank you for tutorial suggestion.

ref to 3) I want to open a new window on the double click of row.

When i double click the cell, it goes in editing mode but i don't want that.

And when cell get clicked then I want to show that the whole row is selected.

ref to 4) background color is based on some flag associated with message like "unread" or "recent." and that also going to change dynamically.

thank you for reply

hope I will get some more info now.

JTable_need_infoa at 2007-7-10 3:58:10 > top of Java-index,Desktop,Core GUI APIs...
# 3

3) See 1. Once the cell is not editable then when you double click the editor won't be invoked. So you add a MouseListener to the table and show your dialog on a double click. There are methods in the JTable API to convert the mouse point to a row and column in the table

4) See this posting for one way:

http://forum.java.sun.com/thread.jspa?forumID=57&threadID=610474

camickra at 2007-7-10 3:58:10 > top of Java-index,Desktop,Core GUI APIs...
# 4
can u tell me which mouse listener and method will help me to get mouse double click?
JTable_need_infoa at 2007-7-10 3:58:10 > top of Java-index,Desktop,Core GUI APIs...
# 5
[url http://java.sun.com/docs/books/tutorial/uiswing/events/handling.html]How to Write a Mouse Listener[/url].
camickra at 2007-7-10 3:58:10 > top of Java-index,Desktop,Core GUI APIs...
# 6
thank you sir
JTable_need_infoa at 2007-7-10 3:58:10 > top of Java-index,Desktop,Core GUI APIs...
# 7

thank you sir for that mouse listener and the tablemodel help

One more question :

I have implemented my own datamodel class extending defaultdatamodel.

Fine with those editing problem.

One more problem arised is previously I was deleting row on request.

model.removerow() was getting called and the setting the model again.

I was removing at that time but now it's not working.

what need to be added.

thank you

-

JTable_need_infoa at 2007-7-10 3:58:10 > top of Java-index,Desktop,Core GUI APIs...
# 8
as the background of row can be changed....can we set the font style also?
JTable_need_infoa at 2007-7-10 3:58:10 > top of Java-index,Desktop,Core GUI APIs...
# 9
The easiest way would be to use text within html tags to set the font you need.
watfora at 2007-7-10 3:58:10 > top of Java-index,Desktop,Core GUI APIs...
# 10
oh i didn't get u?Actually I want that font to be set for the data in the row of JTable.
JTable_need_infoa at 2007-7-10 3:58:10 > top of Java-index,Desktop,Core GUI APIs...
# 11

> model.removerow() was getting called and the setting the model again.

> I was removing at that time but now it's not working.

Well, you have a bug in your code. The method from the DefaultTableModel works.

> Actually I want that font to be set for the data in the row of JTable.

Your requirement still isn't very clear. We don't know if the font changes for the entire row or only for certain cells.

This posting has two different approach for changing the font of a cell:

http://forum.java.sun.com/thread.jspa?forumID=57&threadID=610474

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the posted code retains its original formatting.

camickra at 2007-7-10 3:58:10 > top of Java-index,Desktop,Core GUI APIs...
# 12

messageTable = new JTable(model){

public Class getColumnClass(int column)

{

return getValueAt(0, column).getClass();

}

public Component prepareRenderer(TableCellRenderer renderer, int row, int column)

{

Component c = super.prepareRenderer(renderer, row, column);

try

{

Flags flags = messages[row].getFlags();

String[] uf = flags.getUserFlags(); // get user-flag strings

for (int i = 0; i < uf.length; i++) {

System.out.println("UserFlag : " + uf[i]);

}

}catch(Exception e){}

return c;

}

};

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

at MailClient$1.getColumnClass(MailClient.java:177)

at javax.swing.JTable.getCellRenderer(Unknown Source)

at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown ...............

Not able to identify the reason..

thank you

Message was edited by:

JTable_need_info

JTable_need_infoa at 2007-7-10 3:58:10 > top of Java-index,Desktop,Core GUI APIs...
# 13
> Not able to identify the reason..The error message tells you what the problem is:> Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException> at MailClient$1.getColumnClass(MailClient.java:177)
camickra at 2007-7-10 3:58:10 > top of Java-index,Desktop,Core GUI APIs...