Here you can find the source of repaintSelection(JTree tree)
Parameter | Description |
---|---|
tree | the JTree to repaint the selection of. |
public static void repaintSelection(JTree tree)
//package com.java2s; //License from project: Open Source License import java.awt.Rectangle; import javax.swing.JTree; public class Main { /**/*w w w . ja v a 2s .c om*/ * Repaints the selection. This allows the row selection to have a * background color that changes based on the focus state of the * component. * * @param tree the {@code JTree} to repaint the selection of. */ public static void repaintSelection(JTree tree) { int[] selectedRows = tree.getSelectionRows(); // if there is a selected row, then repaint it. if (selectedRows != null && selectedRows.length > 0) { // grab the bounds of the first and last selected cells in column // one (index zero). Rectangle firstSelectedCell = tree.getRowBounds(selectedRows[0]); Rectangle lastSelectedCell = tree.getRowBounds(selectedRows[selectedRows.length - 1]); // create the rectangle to repaint by unioning the first and last // selected cells in column one and then extending that rectangle // to extend from the left edge of the table all the way to the // right edge. Rectangle repaintRectangle = firstSelectedCell.union(lastSelectedCell); repaintRectangle.x = 0; repaintRectangle.width = tree.getWidth(); // repaint the selection area. tree.repaint(repaintRectangle); } } }