1
當在java文檔中尋找某些東西時,我意識到存在某種我以前從未見過的嵌套,所以如果你能解釋它是什麼或者它是如何調用的,我會非常感激。這種方法嵌套如何工作? [TableRowRenderingTip.java]
這是我在StackOverflow中的第一個問題,所以我很抱歉,如果我違反了任何規則。
代碼:
private JComponent createData(DefaultTableModel model)
{
JTable table = new JTable(model)
{ //What are these brackets for? I know it contains a method but I've never seen a method "nested" with a variable initialization.
public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
{
Component c = super.prepareRenderer(renderer, row, column);
// Color row based on a cell value
if (!isRowSelected(row))
{
c.setBackground(getBackground());
int modelRow = convertRowIndexToModel(row);
String type = (String)getModel().getValueAt(modelRow, 0);
if ("Buy".equals(type)) c.setBackground(Color.GREEN);
if ("Sell".equals(type)) c.setBackground(Color.YELLOW);
}
return c;
}
};
真的不知道如何正確使用的問題編輯器。
提前致謝!
Here's完整的源代碼。
感謝您的快速響應! – MikeMapanare