I am doing a message function , and i want to bold a road where "read=No" and after i click it , it will become read=yes, and unbold ... i done the database part already , but i seriously don't know how to do table rendering .... cauze i am still very fresh in java ... so , anyone can help ? appreciates a lot !
-
@Charles is there reason for edits & remove new Tags, because I'll edits another Swing's rellated threads with these two Tags...– mKorbelSep 8, 2011 at 7:53
-
@mKorbel, from an outsider's point of view, neither this question nor one of the other two questions you edited the new tag into even mention anything about a "windowlistener", and the third only mentions it in an answer: your answer. Remember, tags are meant to help categorize questions so that they can be found by people with questions. If you truly believe that the new tag will help categorize these three rather old questions, please feel free to revert my edits, though I'd highly suggest finding many more questions to add the tag to soon. I'm not the only aggressive new-tag-deleter!– CharlesSep 8, 2011 at 15:19
-
@Charles thanks for your response, yes that exactly about ..., windowlistener is regular Java Swings Listener and mentioned by OP's and by answerer too, in this thread is link (by @camickr) to prepareRenderer funkcionalities, just I clean up Swing rellated question, and added there a few new tags, looks like as part of them I confirmed with multiplay of edits, and for these two I probably forgot :-), never mind, will be created again, thats my enjoy :-)– mKorbelSep 8, 2011 at 15:34
3 Answers
you can make it using HTML
String str = "<html><b>this is bold</b> this is normal </html>";
-
okay ... if(msg.getRead()=="No"){ msg.setRead("<html><b>"+msg.getRead()+"</b></html>"); data[i][4] = msg.getRead(); } i do this on myTableModel, and it doesn't show...– LuciferJan 5, 2011 at 10:02
i want to bold a road where "read=No" and after i click it , it will become read=yes, and unbold ...
Use the Table Row Rendering approach to render a row based on data in the row. Modifying the code from the examples given you would use the following when required:
c.setFont( c.getFont().deriveFont(Font.BOLD) );
Sorry for reviving an old post, but I was looking for something very similar to this and came up with my own solution (though it kind of plays off of Jigar's answer). In my case, I have a table of scripts/programs that displays both the current version (in the 4th column) and the latest version of the script/program (in the 3rd column). I wanted to make it easier to spot the ones that were not up-to-date. All the solutions I saw elsewhere seemed to give a method that involved changing the DefaultCellRenderer
, but didn't mention how to activate it on an already populated table (or really at all, that I could see). As a result, I went about figuring out my own method through the "Keep It Simple Stupid" (KISS for short) way of thinking, and came up with the below code... hopefully someone else finds it useful.
for(int r=0;r<table.getRowCount();r++) {
if(!table.getValueAt(r, 2).equals(table.getValueAt(r, 3))) {
for(int c=0;c<table.getColumnCount();c++) {
table.setValueAt("<html><b>" + table.getValueAt(r, c) + "</b></html>", r, c);
}
}
}
I'm sure there are other, more efficient methods out there... but this was what I was able to come up with with my (still limited) knowledge of Java that actually worked in my situation. Again, sorry for reviving an old post, but I do hope this helps some others in similar situations to my own.