Java 使用JComboBox刷新JPanel时闪烁
我试图用Java模拟excel界面。我有一个绘制方法,它为我绘制网格,绘制所有单元格值,然后绘制所有我的Java 使用JComboBox刷新JPanel时闪烁,java,swing,jpanel,jcombobox,flicker,Java,Swing,Jpanel,Jcombobox,Flicker,我试图用Java模拟excel界面。我有一个绘制方法,它为我绘制网格,绘制所有单元格值,然后绘制所有我的JComboBox对象,这些对象作为HashMap维护 每当我调用我的重绘函数时,我都会看到组合框和其他绘制函数之间的闪烁 有人能给我建议一些方法来消除这种闪烁吗 我的油漆代码如下: public void paintCells(Graphics g) throws Exception { int width = this.getWidth(); int hei
JComboBox
对象,这些对象作为HashMap
维护
每当我调用我的重绘函数时,我都会看到组合框和其他绘制函数之间的闪烁
有人能给我建议一些方法来消除这种闪烁吗
我的油漆代码如下:
public void paintCells(Graphics g) throws Exception {
int width = this.getWidth();
int height = this.getHeight();
if (this.graphics != null) g = this.graphics;
Color oldColor = g.getColor();
Font oldFont = g.getFont();
g.setColor(attr.panelBackgroudColor);
g.fillRect(0, 0, width, height);
paintHeader(g);
paintGrid(g);
int endRow = startRow + getCurrViewRowCount();
int endCol = startCol + getCurrViewColCount();
DisplayRows[] display = new DisplayRows[endCol-startCol+1];
Thread[] displays = new Thread[endCol-startCol+1];
for (int i = startCol; i <= endCol; i++) {
for (int j = startRow; j <= endRow; j++) {
paintCell(g, i, j);
}
}
paintSelectedCell(g);
g.setColor(oldColor);
g.setFont(oldFont);
for (JComboBox dropDown : this.cellGrid.getDropDowns()) {
orderedPair Pair =(orderedPair) this.getHashMapCellValues().get(this.getDropDowns().indexOf(dropDown));
int col = Pair.getFirst();
int row = Pair.getSecond();
CellElement cellValue;
try {
cellValue = new CellElement(col,row,dropDown.getSelectedItem().toString(),CellElement.CELLTYPE.NULL, CellElement.IOTYPE.INPUT);
this.getModel().addElement(cellValue);
} catch (CellTypeException ex) {
Logger.getLogger(DisplayDropDownSpreadSheets.class.getName()).log(Level.SEVERE, null, ex);
}
dropDown.setBounds(this.getCellRect(this.getModel().getElement(col, row)));
((PricingCellModel)this.getModel()).setNull(col, row);
dropDown.repaint();
}
public void paintCells(图形g)引发异常{
int width=this.getWidth();
int height=this.getHeight();
如果(this.graphics!=null)g=this.graphics;
Color oldColor=g.getColor();
Font oldFont=g.getFont();
g、 setColor(属性面板背景颜色);
g、 fillRect(0,0,宽度,高度);
油漆头(g);
油漆网格(g);
int endRow=startRow+getCurrViewRowCount();
int endCol=startCol+getCurrViewColCount();
DisplayRows[]display=新的DisplayRows[endCol startCol+1];
线程[]显示=新线程[endCol startCol+1];
对于(int i=startCol;i)更简单的方法是使用渲染器而不是,请参阅Oracle教程如何使用Comboboxes。要更快地获得更好的帮助,请发布一篇文章。