java - Customized JTable look -


I want to make jetties with some columns, which have its pockets. I can make JCheckBoxes and JCablesBoxes in JTable cells but JButtons do not how do I do it?

In my project, this is how I did it for 4-line with table 3 column Where in the first column there is JToggleButton in each line:

Required items ...

  Private JTable table1; Private default table model Table 1 model; Private JScrollPane scrollPane1; String [] columnName = {"button", "boolean", "int"};   

and under the code where we create the table ...

  {JToggleButton [jTableButton = new JToggleButton] {new JToggleButton ("A") , New jetballball button ("two"), new jetoglabutan ("three"), new jetgo ​​button button ("four"); Table 1 model = new default tabloadmodel (new object [] [] {{jTableButton [0], false, 1}, {jTableButton [1], false, 1}, {jTableButton [2], false, 1}, {jTableButton [ 3], false, 1}}, column name); Table 1 = New JetTable (Table 1 Model) {/ ** * * / Private Stable Last Long Serial WeisserianUID = 1 L; @ Override Public Boolean Kossel Assetible (int line index, int call index) {int value = (integer) table 1 model .getValueAt (lineindex, 2); String blue color = color BLUE; String redColor = Color.RED; String selected COLOR = Color.GREEN; String color value = selected caller; If (value> gt; 0) {colorValue = blueColor; // blue} and {color = red = red color; // red} return! ColorValue.equals (redColor); // Decline red cell editing} @ Override public class  gt; 0) {colorValue = blueColor; // blue} and {color = red = red color; // red} component c = super.prepareRenderer (renderer, line index, vColIndex); If (ICL-selected (line indland, vColIndex)) (if (vColIndex! = 0) {c.setEnabled (! ColorValue.equals (redColor));} Else {c.setEnabled (! ColorValue.equals (redColor)); If (colorValue.equals (redColor)) c.setBackground (Color.decode (colorValue));} if (Jetloglebutton of C Installation and vColIndex == 0) {JToggleButton Button = (JToggleButton) c; Button.setToolTipText (( (JToggleButton) c) .gettext ());} If (Color.decode (colorValue) .getRed ()> gt4 = amp; amp; ;; Color.decode (colorValue) .getGreen ()> = 224 & amp; ; Color decode (color) .getBlue ()> = 224) {c.setForeground (Color.gray);} Else {c.setForeground (Color.white);}} Return C;}}; scrollPane1 SetViewportView (table1); Table1.setPreferredSize (new java.edimation (187, 299)); Table1 .setFont (New JavaFont ("Segoyi UI", 0, 14)); Table1.getColumnModel (). GetColumn (0) .setCellRenderer (New JToggleButtonRenderer ());}   

JToggleButtonRenderer.java

  class JToggleButtonRenderer JToggleButton implements TableCellRenderer {/ ** * * / Private static last long serialVersionUID = 1L; Public component getTableCellRendererComponent (JTable table, object value, boolean is selected, boolean hasfox, int row, int column) {if (value == empty) empty null; If (selected) {// cell (and possibly other cells) is selected} if (haphocus) {// this cell is anchor and the focus of the table is} return (factor) value; } // The following methods have overridden the default for performance reasons @ Override Public Validate Valid () {} @ Override Public Zero Modify () {} @ Override Protected Zero FirePropertyChange (String Properties Name, Object Old Volume, Object New Wally) {} @ Override Public Zero FirePropertyChange (String Property Name, Boolean Old Value, Boolean New Value) {}} As You Can See The important part is the table model,  table1Model   

to add a new line ...

  // id is something that is You button text table 1 mod.ADRO (new object [] {new Jetlog button (ID), incorrect, 1});   

Edit:

Missing JToggleButton cell renderer has been added

Comments