1 16 package org.apache.log4j.lf5.viewer; 17 18 import javax.swing.*; 19 import javax.swing.table.TableModel ; 20 import java.awt.*; 21 22 29 30 32 public class LF5SwingUtils { 33 37 41 45 49 53 60 public static void selectRow(int row, JTable table, JScrollPane pane) { 61 if (table == null || pane == null) { 62 return; 63 } 64 if (contains(row, table.getModel()) == false) { 65 return; 66 } 67 moveAdjustable(row * table.getRowHeight(), pane.getVerticalScrollBar()); 68 selectRow(row, table.getSelectionModel()); 69 repaintLater(table); 73 } 74 75 79 public static void makeScrollBarTrack(Adjustable scrollBar) { 80 if (scrollBar == null) { 81 return; 82 } 83 scrollBar.addAdjustmentListener(new TrackingAdjustmentListener()); 84 } 85 86 91 public static void makeVerticalScrollBarTrack(JScrollPane pane) { 92 if (pane == null) { 93 return; 94 } 95 makeScrollBarTrack(pane.getVerticalScrollBar()); 96 } 97 98 protected static boolean contains(int row, TableModel model) { 102 if (model == null) { 103 return false; 104 } 105 if (row < 0) { 106 return false; 107 } 108 if (row >= model.getRowCount()) { 109 return false; 110 } 111 return true; 112 } 113 114 protected static void selectRow(int row, ListSelectionModel model) { 115 if (model == null) { 116 return; 117 } 118 model.setSelectionInterval(row, row); 119 } 120 121 protected static void moveAdjustable(int location, Adjustable scrollBar) { 122 if (scrollBar == null) { 123 return; 124 } 125 scrollBar.setValue(location); 126 } 127 128 132 protected static void repaintLater(final JComponent component) { 133 SwingUtilities.invokeLater(new Runnable () { 134 public void run() { 135 component.repaint(); 136 } 137 }); 138 } 139 143 } 147 148 | Popular Tags |