Пример #1
0
  protected String layoutCL(
      JLabel label,
      FontMetrics fontMetrics,
      String text,
      Icon icon,
      Rectangle viewR,
      Rectangle iconR,
      Rectangle textR) {
    String s =
        layoutCompoundLabel(
            (JComponent) label,
            fontMetrics,
            splitStringByLines(text),
            icon,
            label.getVerticalAlignment(),
            label.getHorizontalAlignment(),
            label.getVerticalTextPosition(),
            label.getHorizontalTextPosition(),
            viewR,
            iconR,
            textR,
            label.getIconTextGap());

    if (s.equals("")) return text;
    return s;
  }
 /**
  * {@inheritDoc}
  *
  * <p>Paints a diagonal cross over the text if the comp is of type JLabel, does nothing otherwise.
  */
 @Override
 protected void doPaint(Graphics2D g, JComponent comp, int width, int height) {
   if (!(comp instanceof JLabel)) return;
   JLabel label = (JLabel) comp;
   Insets insets = label.getInsets(insetss);
   paintViewR.x = insets.left;
   paintViewR.y = insets.top;
   paintViewR.width = width - (insets.left + insets.right);
   paintViewR.height = height - (insets.top + insets.bottom);
   paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
   paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;
   SwingUtilities.layoutCompoundLabel(
       label,
       label.getFontMetrics(label.getFont()),
       label.getText(),
       null,
       label.getVerticalAlignment(),
       label.getHorizontalAlignment(),
       label.getVerticalTextPosition(),
       label.getHorizontalTextPosition(),
       paintViewR,
       paintIconR,
       paintTextR,
       label.getIconTextGap());
   doPaint(g, paintTextR);
 }
Пример #3
0
 private static int getLabelBaselineResizeBehavior(JLabel label) {
   if (label.getClientProperty("html") != null) {
     return BRB_OTHER;
   }
   switch (label.getVerticalAlignment()) {
     case JLabel.TOP:
       return BRB_CONSTANT_ASCENT;
     case JLabel.BOTTOM:
       return BRB_CONSTANT_DESCENT;
     case JLabel.CENTER:
       return BRB_CENTER_OFFSET;
   }
   return BRB_OTHER;
 }
Пример #4
0
  private static int getLabelBaseline(JLabel label, int height) {
    Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();
    FontMetrics fm = label.getFontMetrics(label.getFont());

    resetRects(label, height);

    SwingUtilities.layoutCompoundLabel(
        label,
        fm,
        "a",
        icon,
        label.getVerticalAlignment(),
        label.getHorizontalAlignment(),
        label.getVerticalTextPosition(),
        label.getHorizontalTextPosition(),
        viewRect,
        iconRect,
        textRect,
        label.getIconTextGap());

    return textRect.y + fm.getAscent();
  }