Button text in JTable renderer not visible. Why?

I have a custom cell renderer set in JTable and it works but instead an "x" visible on buttons being table cells I see "..." (three dots). What did I miss ??

  /***************************************************************************
 * Listener reagujący na dodanie nowej wartości
 **************************************************************************/
private static class ButtonRenderer extends JButton implements
        TableCellRenderer {
    /***********************************************************************
     * Konstruktor
     **********************************************************************/
    public ButtonRenderer() {
        super("x");
    }

    /***********************************************************************
     * @see TableCellRenderer#getTableCellRendererComponent(JTable, Object,
     *      boolean, boolean, int, int)
     **********************************************************************/
    public Component getTableCellRendererComponent(JTable table,
            Object value, boolean isSelected, boolean hasFocus, int row,
            int column) {
        return this;
    }

}


Asked by: Brooke544 | Posted: 28-01-2022






Answer 1

The size of the button isn't large enough to contain the rendered "x" plus the padding around it.

A solution would be to enlarge the table cell or reduce the padding (always assuming that the button has the same size as the table cell).

Answered by: John984 | Posted: 01-03-2022



Similar questions

java - Using sun PDF Renderer to display PDFs with embedded fonts

I'm having trouble using Sun's PDF Renderer package to view PDFs with embedded fonts. I have the following code which creates a BufferedImage out of every page of a PDF for viewing in my application, and it works fine when there are no embedded fonts. However, when the PDF has embedded fonts, it shows no text. Any ideas? Also, it opens fine in Adobe's PDF viewer. File f = new File("C:\\test.pdf"); FileC...


java - What's wrong with this colored JTree? (custom renderer problem)

I want write custom TreeCellRenderer to have Root, nodes and leafs in different color. This is my code: tree.setCellRenderer(new DefaultTreeCellRenderer() { @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { { DefaultMutableTreeNode node = (DefaultMutableTreeNode) va...


java - PDF Renderer screwing up my pdfs?

I am trying to silent print PDF files from within a java application (more specifically a J2EE Webapp). Within this application I am creating PDF files with iText. The files created are form letters, each consisting of exactly one page. To render and print out these PDF files I tried to use the pdf-renderer library. (See here: https://pd...


java - JTable custom header renderer that looks like other headers with nimbus look and feel?

Any time I create a custom header renderer for a JTable it ends up not looking correct with the nimbus look and feel. The default table headers have a silvery gradient, custom renderers do not look that way. In the past I just avoided creating custom header renderers. Is it possible to copy the default look onto my new custom renderer? Basically I want to add a checkbox and have the area around it look like a normal column...


java - JTable custom cell renderer to create row header

Can somebody please explain how I would create row headers? I already have the data and header texts set in the JTable: all I want to know is how I can use a cell renderer to take that first column (i.e. the row header column) and make it look like the column headers (i.e. the first row). Right now its background is white, so it looks like regular data. I want it to appear gray (or non-opaque I guess??). Oh and it shou...


java - GUI Renderer in Android

just curious to know android Graphical components (View) have their own specific renderer or they are using something like AWT, Swing or...?


java - Why does my android openGL ES test renderer crash

Once again I'm trying to get into openGL, but as usual I choke when passing around vertices/vertixes/whatever and every little detail can lead to disaster (wrong format, initialization not properly set up, where memory are saved, etc.). My main goal is to use openGL for 2D graphics to speed up performance compared to regular cpu drawing. Anyways, my openGL Renderer looks like this: package c...


java - JList with custom renderer

I have a JList that shows multiple JPanels on them , i have created a custom renderer that returns a new JPanel. The JPanels are displayed in the JList but they are not accessible, i cant select them and if i have a button or a text area in it i can not press it. I want to try if this works in a JList because i want to do further pagination. I managed to get it work by adding panels to a Jscroll pane, but would love to ma...


java - Paint a single cell (or a single row) in a JTable without the renderer

I have a JTable and i want a cell (or its row) painted in red when the value entered is higher than a certain value. I'm checking that into a TableModelListener to detect TableChange, so I see no way of colouring the table at the renderer (yet I'm sure it is possible, only it is unknown for me). I also saw


java - How should I buffer my data to the renderer?

Thank you for the help in advance! I am making a 2D game in Java with LWJGL, and I am separating the renderer and game logic into separate threads. To do so, I have to put the world data in the view into a buffer, which then gets passed to the renderer thread. The data is made up from the world, which is static and can be passed by reference, but the entities are too dynamic to do so. The maximum nu...






Still can't find your answer? Check out these amazing Java communities for help...



Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)



top