java - Changing JTable cell color -


This is driving me completely mad.

I know that, to change the formatting of table cells, JTable, I have to use my own renderer but I can not implement it properly

This is my The current setup is:.

  Public class MyClass {public static void (String args []) {JTable mytable = new jettbabel (10, 10); MyTable.setDefaultRenderer ([I do not know what's kept here], new custommer ()); }} Class CustomRenderer extend the default TableCellRenderer {public component getTableCellRendererComponent (JTable table, Object value, boolean, elected bullion Hafoks, brick row, Inti column) {component c = super.getTableCellRendererComponent (table, value, selection, Haphocus, line, column); // formatting returns c; }}  

What do I need to use for the first parameter of setDefaultRenderer ? The API just says 'class' I do not know what to put there.

Is anyone just about the simplest of words, how do I implement it? Please provide an example of how I can change the formatting with the main () method.

setDefaultRenderer in the first parameter, class to the class Enter the virtual which you want to override rendering. I.e., if your data contains all the strings, you can put

  myTable.setDefaultRenderer (String. Class, New Kstmrenderr ());  

If you meet the values ​​of your data then the BigDecimal or integer class time to call type ( BigDecimal.class or Integer.class in each case)

and finally, the background color of its renderer to change this .:

  class CustomRenderer extends DefaultTableCellRenderer {public component getTableCellRendererComponent (JTable table, object value, boolean isSelected, HasFocus Boolean, integer form Finance, int column) {component c = super.getTableCellRendererComponent (table, value, IsSelected, Hafoks, row, column); C.setBackground (New Java Quote Color (255, 72, 72)); Return c; }}  
getColumnClass to modify

If you write a renderer that should work for all classes of an interface , you You will also need to work your table model and return the interface class to all the objects that implement this interface:

  public class  

Additionally, you can register a renderer for an IColorable.class and there is no need to register a separate renderer for each implementation.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -