tablecellrenderer

Swing - Setting the color of a cell based on the value of a cell

a 夏天 提交于 2019-12-01 06:47:32
问题 I would like to set the color of a cell based on the value of the cell. Having googled around for a bit i found out that i can do it using something like this: public class TableCellRenderer extends DefaultTableCellRenderer { @Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) { // get the DefaultCellRenderer to give you the basic component Component c = super.getTableCellRendererComponent(table, value,

JTable custom cell renderer focus problem

妖精的绣舞 提交于 2019-12-01 06:21:01
I have a table like this. The second column uses a JTextField renderer and the third column uses a JPasswordField based renderer and editor. Looks good. But the problem is We have to type the values and must hit "ENTER". In that image, I have typed my password but didn't hit Enter. So If I click the 'Save & Close' button, it'll show me an error that password field is empty. Previously I have used only JTextFields and JPasswordFields under JTabbedPane and it worked well. When I had to add more and more stuff, I changed it to a table like this. For now I have put a label to let people know that

JTable custom cell renderer focus problem

北城余情 提交于 2019-12-01 04:48:17
问题 I have a table like this. The second column uses a JTextField renderer and the third column uses a JPasswordField based renderer and editor. Looks good. But the problem is We have to type the values and must hit "ENTER". In that image, I have typed my password but didn't hit Enter. So If I click the 'Save & Close' button, it'll show me an error that password field is empty. Previously I have used only JTextFields and JPasswordFields under JTabbedPane and it worked well. When I had to add more

Java JTable header word wrap

徘徊边缘 提交于 2019-11-30 15:42:12
I am trying to get the header on a table to have word wrap. I have managed to do this but the first data row is expanding. The code for the table is: public class GenerateTable extends JTable { private JCheckBox boxSelect = new JCheckBox(); private JTableHeader hdGen; public class LineWrapCellRenderer extends JTextArea implements TableCellRenderer { private static final long serialVersionUID = 1L; int rowHeight = 0; // current max row height for this scan @Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int

Java JTable header word wrap

折月煮酒 提交于 2019-11-29 22:09:21
问题 I am trying to get the header on a table to have word wrap. I have managed to do this but the first data row is expanding. The code for the table is: public class GenerateTable extends JTable { private JCheckBox boxSelect = new JCheckBox(); private JTableHeader hdGen; public class LineWrapCellRenderer extends JTextArea implements TableCellRenderer { private static final long serialVersionUID = 1L; int rowHeight = 0; // current max row height for this scan @Override public Component

Colored Table Cells

こ雲淡風輕ζ 提交于 2019-11-29 18:15:40
i want to color my table cells according to the Value in Column 1, if the values isn´t equal to the value in Column 1 the color should be cyan, but my code doesnt work: table = new JTable(){ public TableCellRenderer getCellRenderer(int row, int column) { TableCellRenderer tcr=null; Color c; if(column>=1&&getValueAt(row, column)!=null &&getValueAt(row, 1)!=null &&!getValueAt(row, column).equals(getValueAt(row, 1))) c=Color.CYAN; else c=Color.white; if(getValueAt(row, column) instanceof Boolean) { tcr= super.getDefaultRenderer(Boolean.class); } else { tcr= super.getCellRenderer(row, column); }

Alignment date parts in JTable column formatted in propotional font

此生再无相见时 提交于 2019-11-29 16:42:48
I need to make the date parts (dd, MMMM, yyyy) to be vertically aligned. I asked a question at Fixed length of month and day in date format? to insert padding letters, but I found that it doesn't help in case of proportional font (the width of the letters are different). For example, with Lucida Fax font: Making different labels for different date parts is considering but it's too manual. It's hard to make the text wrapped if the column width is small.... Thanks note as for all Renderers (excluding preparedRenderer)you have to/be sure that you have to call that after any column/row changes in

JTable Set Cell Color At Specific Value

大憨熊 提交于 2019-11-29 14:33:58
问题 I'm trying to write a method which for given parameters (value, color), sets color on the background of a cell which has value equal to cellValue. What my method actually does is, it sets color on the background of a cells for whole row and when I select the row on the table, and I want method to only set color at specific column (where cellValue is equal to value) each time I call the method. void setCellBackgroundColor(boolean cellValue, final Color color) { List<List<Object>> data = tView

Coloring jTable row

倾然丶 夕夏残阳落幕 提交于 2019-11-29 11:34:07
I want to color specific rows in jTable..i did it for columns by using this code, private class CustomCellRenderer extends DefaultTableCellRenderer { /* (non-Javadoc) * @see javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int) */ @Override public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected, boolean hasFocus, int row, int column) { Component rendererComp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus,row, column); //Set foreground color //

Swing JTable - Highlight selected cell in a different color from rest of the selected row?

自闭症网瘾萝莉.ら 提交于 2019-11-29 06:52:46
I have a basic swing JTable and the requirement is that when clicked on any cell, the entire row should be highlighted, and also that the cell which was clicked should be a different color from the rest of the highlighted row. Currently, I have isRowSelectionAllowed as true I tried using a custom TableCellRenderer which is as follows: public class CustomTableCellRenderer extends DefaultTableCellRenderer { public static final DefaultTableCellRenderer DEFAULT_RENDERER = new DefaultTableCellRenderer(); @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean