开发者

Erasing JTable BOTTOM white border

After erasing borders and headers, my JTable looks like this:

Erasing JTable BOTTOM white border

As you can see, a white border is seen at the bottom of the table, and I see no reason at my code for this to happen. How can I erase that?

The code for the JTable is:

Object[][] datosMeasurements = {};
    DefaultTableModel model = new DefaultTableModel(datosMeasurements, nombresColumnasTablas);
    tablaMeasurements = new JTable(model){
      public boolean isCellEditable(int rowIndex, int colIndex) {
            if(colIndex==1){
                return true;
            }
            return false;   //Disallow the editing of any cell
      }
    };
    model.addTableModelListener(new CambioTablaMeasurementListener());
    TableCellRenderer rendererMeasurements = new paramRenderer();
    tablaMeasurements.setDefaultRenderer(Object.class, rendererMeasurements);
    ((DefaultCellEditor) tablaMeasurements.getDefaultEditor(Object.class)).setClickCountToStart(1);

    JScrollPane scrollMeasurements = new JScrollPane(tablaMeasurements);
    tablaMeasurements.setTableHeader(null);
    scrollMeasurements.setColumnHeaderView(null);
    tablaMeasurements.setPrefe开发者_C百科rredScrollableViewportSize(new Dimension(100,100));

And for its renderer:

class paramRenderer extends DefaultTableCellRenderer
{
    private final DecimalFormat formatter = new DecimalFormat( "#.000" );
    public Component getTableCellRendererComponent(
                    JTable table,
                    Object value,
                    boolean isSelected,
                    boolean hasFocus,
                    int row,
                    int column)
    {
        //value = formatter.format((Number)value);
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

        setEnabled(table == null || table.isEnabled());

        if (column == 0)
            setHorizontalAlignment( RIGHT );
        else if (column == 1)
            setHorizontalAlignment( CENTER );
        else
            setHorizontalAlignment( LEFT );    

        for (int i=0; i<3; i++) {
              TableColumn columna = table.getColumnModel().getColumn(i);
              if (i==0) columna.setPreferredWidth(65);
              if (i==1) columna.setPreferredWidth(75);
              if (i==2) columna.setPreferredWidth(30);
            }

        if(isSelected)
        {
            setBackground(table.getBackground());
            setForeground(table.getForeground());
            if (row==0 || row==2) setBackground(new java.awt.Color(211, 217, 255));
            else setBackground(java.awt.Color.white); 
        }
        else
        {
            setBackground(table.getBackground());
            setForeground(table.getForeground());
            if (row==0 || row==2) setBackground(new java.awt.Color(211, 217, 255));
            else setBackground(java.awt.Color.white); 
        }

        return this;
    }
    public void setValue() {    
        formatter.setMinimumFractionDigits(1);
        formatter.setMaximumFractionDigits(3);
    }
}

}


calculate the prefScrollableViewportSize in terms of rowHeight, something like

int visibleRowCount = 10;
table.setPreferredScrollableViewportSize(
     new Dimension(myWidth, visibleRowCount * table.getRowHeight()));


That is probable the tables "viewPort". You can try with:

yourTable.setFillsViewportHeight(true);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜