@Override
  protected int getMaxAvailablePageWidth(
      JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    Insets insets = list.getInsets(); // OWLFrameList.ITEM_BORDER.getBorderInsets();
    int componentWidth = list.getWidth();
    JViewport vp = (JViewport) SwingUtilities.getAncestorOfClass(JViewport.class, list);
    if (vp != null) {
      componentWidth = vp.getViewRect().width;
    }

    return componentWidth
        - list.getInsets().left
        - list.getInsets().right
        - insets.left
        + insets.right
        - 20;
  }
예제 #2
0
 private static int getListBaseline(JList list, int height) {
   int rowHeight = list.getFixedCellHeight();
   if (LIST_LABEL == null) {
     LIST_LABEL = new JLabel("X");
     LIST_LABEL.setBorder(new EmptyBorder(1, 1, 1, 1));
   }
   JLabel label = LIST_LABEL;
   label.setFont(list.getFont());
   // JList actually has much more complex behavior here.
   // If rowHeight != -1 the rowHeight is either the max of all cell
   // heights (layout orientation != VERTICAL), or is variable depending
   // upon the cell.  We assume a default size.
   // We could theoretically query the real renderer, but that would
   // not work for an empty model and the results may vary with
   // the content.
   if (rowHeight == -1) {
     rowHeight = label.getPreferredSize().height;
   }
   return getLabelBaseline(label, rowHeight) + list.getInsets().top;
 }