Я работаю над настройкой Look and Feel для своего приложения, используя BasicLookandFeel.Прямо сейчас я работаю над JList, расширяя BasicJListUI. Я пытаюсь закрасить свой JList, но его рисование поверх компонентов. введите описание изображения здесь
Прямо сейчас я расширяю эти методы
protected void paintCell(Graphics g,int row,Rectangle rowBounds,ListCellRenderer cellRenderer,
ListModel dataModel,ListSelectionModel selModel,int leadIndex)
{
Object value = dataModel.getElementAt(row);
boolean cellHasFocus = list.hasFocus() && (row == leadIndex);
boolean isSelected = selModel.isSelectedIndex(row);
Component rendererComponent =
cellRenderer.getListCellRendererComponent(list, value, row, isSelected, cellHasFocus);
int cx = rowBounds.x;
int cy = rowBounds.y;
int cw = rowBounds.width;
int ch = rowBounds.height;
if (isFileList)
{
// Shrink renderer to preferred size. This is mostly used on Windows
// where selection is only shown around the file name, instead of
// across the whole list cell.
int w = Math.min(cw, rendererComponent.getPreferredSize().width + 4);
if (!isLeftToRight)
{
cx += (cw - w);
}
cw = w;
}
rendererPane.paintComponent(g, rendererComponent, list, cx, cy, cw, ch, true);
}
public void paint(Graphics g, JComponent c)
{
Shape clip = g.getClip();
super.paint(g,c);
paintImpl(g, c);
g.setClip(clip);
paintDropLine(g);
}
private void paintImpl(Graphics g, JComponent c)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
int width = list.getWidth();
int height = list.getHeight();
g2d.setPaint(mainGradient);
g2d.fillRect(0, 0, width, height);
switch (layoutOrientation)
{
case JList.VERTICAL_WRAP:
if (list.getHeight() != listHeight)
{
updateLayoutStateNeeded |= heightChanged;
redrawList();
}
break;
case JList.HORIZONTAL_WRAP:
if (list.getWidth() != listWidth)
{
updateLayoutStateNeeded |= widthChanged;
redrawList();
}
break;
default:
break;
}
maybeUpdateLayoutState();
ListCellRenderer renderer = list.getCellRenderer();
ListModel dataModel = list.getModel();
ListSelectionModel selModel = list.getSelectionModel();
int size;
if ((renderer == null) || (size = dataModel.getSize()) == 0)
{
return;
}
// Determine how many columns we need to paint
Rectangle paintBounds = g.getClipBounds();
int startColumn, endColumn;
if (c.getComponentOrientation().isLeftToRight())
{
startColumn = convertLocationToColumn(paintBounds.x,
paintBounds.y);
endColumn = convertLocationToColumn(paintBounds.x +
paintBounds.width,
paintBounds.y);
}
else
{
startColumn = convertLocationToColumn(paintBounds.x +
paintBounds.width,
paintBounds.y);
endColumn = convertLocationToColumn(paintBounds.x,
paintBounds.y);
}
int maxY = paintBounds.y + paintBounds.height;
int leadIndex = adjustIndex(list.getLeadSelectionIndex(), list);
int rowIncrement = (layoutOrientation == JList.HORIZONTAL_WRAP) ?
columnCount : 1;
for (int colCounter = startColumn; colCounter <= endColumn;
colCounter++)
{
// And then how many rows in this columnn
int row = convertLocationToRowInColumn(paintBounds.y, colCounter);
int rowCount = getRowCount(colCounter);
int index = getModelIndex(colCounter, row);
Rectangle rowBounds = getCellBounds(list, index, index);
if (rowBounds == null)
{
// Not valid, bail!
return;
}
while (row < rowCount && rowBounds.y < maxY &&
index < size)
{
rowBounds.height = getHeight(colCounter, row);
g.setClip(rowBounds.x, rowBounds.y, rowBounds.width,
rowBounds.height);
g.clipRect(paintBounds.x, paintBounds.y, paintBounds.width,
paintBounds.height);
paintCell(g, index, rowBounds, renderer, dataModel, selModel,
leadIndex);
rowBounds.y += rowBounds.height;
index += rowIncrement;
row++;
}
}
// Empty out the renderer pane, allowing renderers to be gc'ed.
rendererPane.removeAll();
}
Как рисовать под моими компонентами, чтобы они не были скрыты?