Background « JTable « Java Swing Q&A





1. How to set the colour of my 1st row in my JTable to yellow(or any colour)?    stackoverflow.com

I am able to set one column to yellow but I am unable to set a row to yellow. The following code does it for the column:

TableColumn col = mytable.getColumnModel().getColumn(0);

col.setCellRenderer(new MyTableCellRenderer());
How do ...

2. How to paint a gridline as a background on JPanel    stackoverflow.com

I have a problem. I used Gridbaglayout in my JFrame. One of the component is JPanel. I wanted to draw a gridline as a background for my JPanel. e.g in the program ...

3. How to set the background color of target cells in a jtable?    stackoverflow.com

I don't want to set the background color for all the cells in the jtable, just the ones I choose. How do i go about doing this?

4. JTable with striped background    stackoverflow.com

Using a different background color for odd and even rows is a commonly used trick to improve readability of large tables. I want to use this effect in Swing's JTable. I ...

5. Java + JCommon: How set cell background in SortableTable?    stackoverflow.com

How set cell background color in SortableTable?

6. Change the background color of a row in a JTable    stackoverflow.com

I have a JTable with 3 columns. I've set the TableCellRenderer for all the 3 columns like this (maybe not very effective?).

 for (int i = 0; i < 3; i++) ...

7. Using intercellSpacing in a JTable with a custom row background color causes unexpected results    stackoverflow.com

I have a JTable where I want to highlight some rows using a custom background-color. This I have done with the following class:

public class MyTable extends JTable {

    ...

8. Background image in JScrollpane with JTable    stackoverflow.com

Im trying to add a centered background image behind a JTable in a JScrollPane. The position of the background relative to the Viewport should be centered and static. Ive tried adding the JScrollPane ...

9. I wanna hide this little white-thing on the JTable    stackoverflow.com

The picture shows a thin (1 pixel?) white margin (marked in blue) inside the border of a JTable. How can the margin be eliminated, or the colour be changed? I have tried:

  • Changing the ...





10. JTable: changing cell background when a button is clicked    stackoverflow.com

I know changing cell backgrounds in jtable is done by creating a new cellrenderer class. I've done that. I've read about DefaultTableRenderer "color memory" issue, but I can't figure out how ...

11. Java (more) JTable cell background colors    stackoverflow.com

Alright this is a follow-up to my last question: JTable: Changing cell background when a button is clicked I can now change background color of selected cells in the JTable by using ...

12. How to get the background color of a JList's unselected cell?    stackoverflow.com

I am trying to find the color used by cells that are unselected. This is usually white, however when I call UIManager.getColor("List.background"), it appears to be the same grey color used ...

13. JTable TableCellRenderer background with NimbusLookAndFeel color problem    stackoverflow.com

I'm using NimbusLookAndFeel. With this look and feel JTable's cell background are alternatively white and light grey (it depends on the row number). Now, I'm writing some custom cell renderer implementing TableCellRenderer. ...

14. JTable - Boolean Cell Type - Background    stackoverflow.com

I'm using the Nimbus L&F with a JTable that has a boolean (checkbox) element as one of its columns. Nimbus JTable with check box The issue I'm having is that the ...

15. Set color of a JTable column and row with TableCellRender    stackoverflow.com

I am wondering if I can set the specified row and column color without defining my own custom TableCellRender. Currently I am using this code

TableCellRenderer cellRenderer = this.devicePropertyTable.getCellRenderer(1, 1);
Component cellRenderComponent = cellRenderer.getTableCellRendererComponent(this.devicePropertyTable, ...

16. JTable how to hide column in view but keep it in model for use it in background    stackoverflow.com

I have a JTable and am passing a data array into the TableModel. I wish to retain all columns in the data model as I need them all for background data ...





17. refreshing background color for a row in jtable    stackoverflow.com

i am trying to set the color of row of a Swing Jtable. i use this class to extend Jtable as suggest on the net.

    public class ColorTable extends ...

18. How to add background image in JTable when printing?    stackoverflow.com

I want to print a JTable with background image or water mark. My code is:

public void actionPerformed(ActionEvent ae)
{
    boolean status=false;

    MessageFormat header = null;
  ...

19. JTable change cell background at mouse click - after release change background back?    stackoverflow.com

my question is, how to solve following problem: If i click on a cell in a JTable, i want to change its background. If i release the mousebutton, i want the background ...

20. Java: Override table cell renderer, but with default background and properties    stackoverflow.com

If you want to add a custom renderer, normally, you'd either extend some JComponent (like JLabel) and implement TableCellRenderer, or you'd extend DefaultTableCellRenderer. However, in either case, what I find ...

21. How can I change JTable's header background color?    stackoverflow.com

I've tried:

table.getTableHeader().setBackground(Color.BLACK);
Doesn't work. EDIT: This code doesn't work in my project only. Works in other projects. I may have changed a property that stops the color from changing. Or maybe NetBeans has ...

22. how to add gradient background to JTable column header?    stackoverflow.com

Hi how to set gradient background to column header ? I have Jtable:

JTable table = new JTable(4, 5);
and try to setColor: table.getTableHeader().setBackground(Color.blue); but with no succes color of column header is still ...

23. JTable how to change BackGround Color    stackoverflow.com

I inspired by MeBigFatGuy interesting question, in this conection I have very specific question about Graphisc2D, how to change BackGround Color by depends if is JTables Row visible in the ...

24. Put background image in a jTable    forums.netbeans.org

Hi, I created a netbeans project using the pallete and put a jTable. I need to put a backgrund image. similiar to this: http://simpletable.sourceforge.net/images/table02.jpg i search in google, but proballu im still to newbie i manage to put an image background, but the cells stay over the image, like opacy isn't working. i copy a java class and added to my ...

25. JTable - how to set background color    coderanch.com

26. JTable Background in JDK 1.3.0    coderanch.com

Hi, I think you are using a scrollpane over the table. The grey portion is not the table area but the view port area. so set the background for the view port. the code for getting the background color is table.setBackground(Color.red); table.getViewport().setBackground(Color.red); I think this solves ur problem. Regards, Jagan Mohan Reddy.

27. JTree Row Background Colour    coderanch.com

28. background color of cells of Jtable    coderanch.com

Hi My Problem is. I have a JTable with 2 columns ( Rows can be 1-10 depending upon the size of input vector) I have provided two button in my Frame 1)Update Row 2) Update whole Table. Now i want I want that if a user makes a change in any cell say cell( row 3,Col 1) ;and moves to next ...

29. Background Pattern for a Cell in JTable    coderanch.com

Hi Rob, I know that this is how I can put an icon in the cell.But I want my pattern to occupy the entire cell space.It should increase or decrease with the cell width. Any example related to this would help. Thanks Pomchi [ January 09, 2002: Message edited by: Pomchi Bedi ]

30. Changing background color of a JTable row.    coderanch.com

public class CustomTableCellRenderer extends DefaultTableCellRenderer { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); String seats = (String)value; try { if (Integer.parseInt(seats)==0) { System.out.println("Number of seats are 0 : Data Client : Constructor"); cell.setBackground(Color.red); } else { cell.setBackground(Color.white); } } catch (NumberFormatException nfe) { } ...

32. JTable + background colour    coderanch.com

I am using JTable to display a list of records that are inserted and removed at run time. I have no way of knowing how many will be in there at any given time. I have set the background colour to white which is fine when there are records in the table. However, when there are say only 2 records in ...

33. Background color on JTable    coderanch.com

34. Jtable background image    coderanch.com

I would suggest associating the background image with the JScrollPane's JViewport. Since the view port itself doesn't scroll, that takes care of the problem. Here is some sample code: I like to use a border to draw the image, and in that way avoid excess subclassing, but your mileage may vary. import java.awt.*; import java.awt.image.*; import javax.swing.border.*; public class CentredBackgroundBorder implements ...

35. JTable -background color    coderanch.com

38. jTable background? problem    coderanch.com

39. Changing background colour of a table cell    coderanch.com

Hi all, Want to change the background colour of a specific cell when the user double clicks on the cell. I extended the table so that it returns the "specialrenderer" for this particular cell(see code). Also assumed that on double clicking on a cell,that will become the currently selected cell on the table. But the cell background colour is not changing.Guess ...

40. Changing background color of cell in JTable    coderanch.com

Hi There, I have a jTable in my application. I want to change the color (if value is positive then blue, otherwise green) of particular column. Here is the code: import javax.swing.BorderFactory; import javax.swing.JLabel; import javax.swing.JTable; import javax.swing.border.Border; import javax.swing.table.TableCellRenderer; import java.awt.Color; import java.awt.Component; public class ColorRenderer extends JLabel implements TableCellRenderer { public ColorRenderer() { setOpaque(true); //MUST do this for background ...

42. How to change column heading Font,Background,Foreground.    coderanch.com

Hi, i am creating a screenshot ,in which all the text should display in the same font style,same Background color,same Foreground color. but my JTable column headings are not changing. any suggestions are welcome....... and my code is import java.awt.BorderLayout; import java.awt.FlowLayout; import java.util.*; import java.text.*; import javax.swing.*; public class ScreenFile { private static JButton delete; private static JButton later; public ...

43. JTable inside JScrollPane - background coloring problem    coderanch.com

I have a situation with a table that's narrower and shorter than the enclosing scroll pane's viewport, and column auto-resizing is turned off, so there's empty space below and to the right of the table. I'd like to fill the empty space with a single background color. I can fill in the bottom using scrollPane.setBackground(), and I can set most of ...

44. CellRenderer, change background color per row    java-forums.org

Hi, I would like to change JTable's background color per row and the other row's color will not change. I created a SSCCE to describe my problem, in this program user will input the row that he want to change then that row will change its background color, that part is ok, but when user input another row the background color ...

45. Background under column header    java-forums.org

I have small problem. I would like to change color under column header when I am draging column to change its order. Try this simple code and drag columns. You will notice GRAY rectangle under header. How can I change it ? Java Code: import java.awt.Color; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.table.JTableHeader; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import ...

46. jtable cell background    java-forums.org

47. jxtable background color question    java-forums.org

I have a jxtable. If validation failed, I like the cell to be red at all time. If validation passed, I like the cell to be white if it is not selected, yellow if it is selected. Yellow and white works fine but red only shows up when the cell/row is selected. Following is my custom renderer. What do I do ...

49. Change background of JComboBox in a Jtable    forums.oracle.com

synonymsTable.setAllColumns(synonymColumns); synonymsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); TableColumn SYNONYMNAME = synonymsTable.getColumnModel().getColumn(0); TableColumn SYNONYMTYPENAME = synonymsTable.getColumnModel().getColumn(1); SYNONYMTYPENAME.setCellEditor(new synonymnTypesEditor(synonymnTypeCodes)); SYNONYMTYPENAME.setCellRenderer(new synonymnTypesRenderer(synonymnTypeCodes)); public class synonymnTypesRenderer extends ValuePairCombo implements TableCellRenderer { public synonymnTypesRenderer(ValuePair[] items) { super(items); } public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { setBorder(null); if (currentMode == ERMEnv.EDIT_MODE){ setForeground(com.emax.util.client.ComponentColorHandler.ENABLED_TEXT_COLOR); super.setBackground(table.getSelectionBackground()); }else{ setForeground( com.emax.util.client.ComponentColorHandler.DISABLED_TEXT_COLOR); setBackground(Color.Gray); }

50. Changing the background of a JTable cell    forums.oracle.com

51. JTable - change row background color    forums.oracle.com

/** * GrayWhiteTable renders its rows with a sequential color combination of white * and gray. Rows with even indicies are rendered white, odd indicies light grey. * Note: Do not use GrayWhiteTable for tables with custom renderers such as * check boxes. Use JTable instead and modify DefaultTableCellRenderer. Just keep * in mind that in order to display a table ...