// Initializes this component. private void jbInit() { segmentTable.addFocusListener( new FocusListener() { public void focusGained(FocusEvent e) { segmentTable_focusGained(e); } public void focusLost(FocusEvent e) { segmentTable_focusLost(e); } }); segmentTable.setTableHeader(null); scrollPane = new JScrollPane(segmentTable); scrollPane.setMinimumSize(new Dimension(getTableWidth(), 0)); setLayout(new BorderLayout(0, 0)); determineColumnWidth(); nameLbl.setPreferredSize(new Dimension(getTableWidth(), 25)); nameLbl.setMinimumSize(new Dimension(getTableWidth(), 0)); nameLbl.setFont(Utilities.labelsFont); segmentTable.setFont(Utilities.valueFont); setBorder(BorderFactory.createEtchedBorder()); setMinimumSize(new Dimension(getTableWidth(), 0)); this.add(nameLbl, BorderLayout.NORTH); this.add(scrollPane, BorderLayout.CENTER); }
/** Returns the coordinates of the top left corner of the value at the given index. */ public Point getCoordinates(int index) { JScrollBar bar = scrollPane.getVerticalScrollBar(); Rectangle r = segmentTable.getCellRect(index, 1, true); segmentTable.scrollRectToVisible(r); setTopLevelLocation(); return new Point( (int) (r.getX() + topLevelLocation.getX()), (int) (r.getY() + topLevelLocation.getY())); }
/** Sets the number of visible rows. */ public void setVisibleRows(int num) { int tableHeight = num * segmentTable.getRowHeight(); scrollPane.setSize(getTableWidth(), tableHeight + 3); setPreferredSize(new Dimension(getTableWidth(), tableHeight + 30)); setSize(getTableWidth(), tableHeight + 30); }