Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not entirely sure what you mean by "one pixel off" - but achieve zero intercell spacing without any visual artefacts you have to both zero the margins and turn off the grid lines:</p> <pre><code>table.setIntercellSpacing(new Dimension(0, 0)); table.setShowGrid(false) </code></pre> <p><strong>Edit</strong></p> <p>Okay, looking closer, there are several issues with your code</p> <ul> <li>you do the column sizing indirectly instead of directly (and yet another nice example why to never-ever do a component.setPreferredSize :-)</li> <li>the renderer's border takes some size</li> </ul> <p>to fix the first, configure each <em>column</em>'s width, table layout will automagically configure its itself</p> <pre><code> final int rows = 16; final int columns = 16; Tile tile = new Tile(0); int tileHeight = tile.getIcon().getIconHeight(); int tileWidth = tile.getIcon().getIconWidth(); JTable table = new JTable(rows, columns); // remove all margin table.setIntercellSpacing(new Dimension(0, 0)); table.setShowGrid(false); table.setTableHeader(null); // set the rowHeight table.setRowHeight(tileHeight); // turn off auto-resize table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // configure each column with renderer and prefWidth for (int j = 0; j &lt; columns; j++) { TableColumn column = table.getColumnModel().getColumn(j); column.setCellRenderer(new MyRenderer()); column.setPreferredWidth(tileWidth); } </code></pre> <p>for the second, null the border in each call:</p> <pre><code>public static class MyRenderer extends DefaultTableCellRenderer { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); setBorder(null); Tile tile = (Tile) value; setIcon(tile.getIcon()); return this; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload