gpt4 book ai didi

java - 删除 JTable 底部白色边框

转载 作者:行者123 更新时间:2023-11-29 06:11:35 25 4
gpt4 key购买 nike

删除边框和标题后,我的 JTable 如下所示:

enter image description here

如您所见,表格底部有一个白色边框,我认为我的代码没有理由发生这种情况。我怎样才能删除它?

JTable 的代码是:

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.setPreferredScrollableViewportSize(new Dimension(100,100));

对于它的渲染器:

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);
}
}

最佳答案

根据 rowHeight 计算 prefScrollableViewportSize,类似于

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

关于java - 删除 JTable 底部白色边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6621779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com