private static void scrollToSelection(JList list) { int selectedRow = list.getSelectedIndex(); if (selectedRow >= 0) { list.scrollRectToVisible(list.getCellBounds(selectedRow, 0)); } }
private static void scrollToSelection(JList list) { int selectedRow = list.getSelectedIndex(); if (selectedRow >= 0) { list.scrollRectToVisible(list.getCellBounds(selectedRow, 0)); } }
final JList list = new JList(new String[] {"a","b","c"}); list.addMouseMotionListener(new MouseMotionListener() { @Override public void mouseMoved(MouseEvent e) { final int x = e.getX(); final int y = e.getY(); // only display a hand if the cursor is over the items final Rectangle cellBounds = list.getCellBounds(0, list.getModel().getSize() - 1); if (cellBounds != null && cellBounds.contains(x, y)) { list.setCursor(new Cursor(Cursor.HAND_CURSOR)); } else { list.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } } @Override public void mouseDragged(MouseEvent e) { } });
public static void setSelection(JList list, Object element) { for (int i = 0; i < list.getModel().getSize(); i++) { Object value = (Object) list.getModel().getElementAt(i); if (value == element) { list.setSelectedIndex(i); list.scrollRectToVisible(list.getCellBounds(i, i)); return; } } }
/** User exits the dragging */ public void dragExit(DropTargetEvent dte) { if (lastIndex >= 0) { cellRenderer.draggingExit(); comp.repaint(comp.getCellBounds(lastIndex, lastIndex)); } }
public int locationToIndex(Point location) { int index = super.locationToIndex(location); if (index != -1 && !getCellBounds(index, index).contains(location)) { return -1;
/** User is starting to drag over us */ public void dragEnter(DropTargetDragEvent dtde) { if (!checkConditions(dtde)) { dtde.rejectDrag(); } else { lastIndex = comp.locationToIndex(dtde.getLocation()); cellRenderer.draggingEnter(lastIndex, ids.getDragGestureEvent().getDragOrigin(), dtde.getLocation()); comp.repaint(comp.getCellBounds(lastIndex, lastIndex)); } }
/** User drag over us */ public void dragOver(DropTargetDragEvent dtde) { if (!checkConditions(dtde)) { dtde.rejectDrag(); if (lastIndex >= 0) { cellRenderer.draggingExit(); comp.repaint(comp.getCellBounds(lastIndex, lastIndex)); lastIndex = -1; } } else { dtde.acceptDrag(DnDConstants.ACTION_MOVE); int index = comp.locationToIndex(dtde.getLocation()); if (lastIndex == index) { cellRenderer.draggingOver(index, ids.getDragGestureEvent().getDragOrigin(), dtde.getLocation()); } else { if (lastIndex < 0) { lastIndex = index; } cellRenderer.draggingExit(); cellRenderer.draggingEnter(index, ids.getDragGestureEvent().getDragOrigin(), dtde.getLocation()); comp.repaint(comp.getCellBounds(lastIndex, index)); lastIndex = index; } } }
public void run() { if (list.getCellBounds(0, 0) != null) { controlledTableView.setRowHeight(list.getCellBounds(0, 0).height); } changeTableModel(); tableChanging = false; } }
private Point getSelectedLocation() { int selected = list.getSelectedIndex(); Rectangle b = list.getCellBounds(selected, selected); if (b != null) { return new Point(b.x, b.y); } return new Point(0, 0); }
private void decrementSelection() { if (popupList.getModel().getSize() > 0) { int selIndex = popupList.getSelectedIndex(); selIndex--; if (selIndex < 0) { selIndex = popupList.getModel().getSize() - 1; } popupList.setSelectedIndex(selIndex); popupList.scrollRectToVisible(popupList.getCellBounds(selIndex, selIndex)); } }
private void incrementSelection() { if (popupList.getModel().getSize() > 0) { int selIndex = popupList.getSelectedIndex(); selIndex++; if (selIndex > popupList.getModel().getSize() - 1) { selIndex = 0; } popupList.setSelectedIndex(selIndex); popupList.scrollRectToVisible(popupList.getCellBounds(selIndex, selIndex)); } }
private static Rectangle getRectangleAt(JList list, int x, int y) { Rectangle rect = null; try { int index = list.locationToIndex(new Point(x, y)); rect = list.getCellBounds(index, index); } catch (Exception e) { } return rect; }
void scrollUp() { int currIndex = resultList.getSelectedIndex(); if (currIndex == -1 || currIndex == 0) return; resultList.setSelectedIndex(currIndex - 1); Rectangle r = resultList.getCellBounds(currIndex - 1, currIndex - 1); if (r != null) { resultList.scrollRectToVisible(r); } }
void selectNext() { int oldSel = jList1.getSelectedIndex(); if (oldSel >= 0 && oldSel < jList1.getModel().getSize() - 1) { int idx = oldSel + 1; jList1.setSelectedIndex(idx); jList1.scrollRectToVisible(jList1.getCellBounds(idx, idx)); } else if(oldSel < 0 && rModel.getSize() > 0) { jList1.setSelectedIndex(0); } }
protected void showPopup(MouseEvent e) { Point p = new Point(e.getX(), e.getY()); int i = list.locationToIndex(p); if (!list.isSelectedIndex(i)) { list.setSelectedIndex(i); } // the area of selected Rectangle r = list.getCellBounds(i, i); boolean contextMenu = (r == null) || !r.contains(p); createPopup(e.getX(), e.getY(), contextMenu); }
protected void showPopup (MouseEvent e) { Point p = new Point (e.getX (), e.getY ()); int i = list.locationToIndex (p); if (!list.isSelectedIndex (i)) { list.setSelectedIndex (i); } // the area of selected Rectangle r = list.getCellBounds(i, i); boolean contextMenu = (r == null) || !r.contains (p); createPopup(e.getX(), e.getY(), contextMenu); }
/** * {@inheritDoc} */ @Override public Rectangle getCellBounds() { JList list = getPopupListFor(comboBox); if (list == null) { assert false; return new Rectangle(comboBox.getSize()); } return list.getCellBounds(row, row); }
@Override public void keyTyped(KeyEvent e) { if (e.getKeyChar() == KeyEvent.VK_SPACE) { AuthenticationCheckboxListItem item = authenticationsList.getSelectedValue(); if (item != null) { int index = authenticationsList.getSelectedIndex(); item.setSelected(!item.isSelected()); authenticationsList.repaint(authenticationsList.getCellBounds(index, index)); } } } });
/** User exits the dragging */ public void dragExit(DropTargetEvent dte) { ExplorerDnDManager.getDefault().setMaybeExternalDragAndDrop( false ); if (lastIndex >= 0) { NodeRenderer.dragExit(); list.repaint(list.getCellBounds(lastIndex, lastIndex)); } }