Java で Excel インターフェイスを模倣しようとしています。グリッドをペイントし、すべてのセル値をペイントしてから、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();
}
Paint header は Excel インターフェイスのヘッダーを描画し、paint grid は線を描画し、paintcell はインターフェイスの各セルを描画します。