示例#1
0
 @Override
 public int getBaseline() {
   FontMetrics fm = b.getFontMetrics(b.getFont());
   int border = (b.getPreferredSize().height - fm.getHeight()) / 2;
   int bestGuess = border + fm.getAscent();
   if (PlatformUtils.isMac()) bestGuess -= 1;
   return bestGuess;
 }
示例#2
0
 private static int getComboBoxBaseline(JComboBox combobox, int height) {
   Insets insets = combobox.getInsets();
   int y = insets.top;
   height -= (insets.top + insets.bottom);
   if (combobox.isEditable()) {
     ComboBoxEditor editor = combobox.getEditor();
     if (editor != null && (editor.getEditorComponent() instanceof JTextField)) {
       JTextField tf = (JTextField) editor.getEditorComponent();
       return y + getSingleLineTextBaseline(tf, height);
     }
   }
   // Use the renderer to calculate baseline
   if (isMetal()) {
     if (isOceanTheme()) {
       y += 2;
       height -= 4;
     }
   } else if (isWindows()) {
     // This doesn't guarantee an XP style will be active,
     // but we don't offer public API to detect if XP is active.
     String osVersion = System.getProperty("os.version");
     if (osVersion != null) {
       Float version = Float.valueOf(osVersion);
       if (version.floatValue() > 4.0) {
         y += 2;
         height -= 4;
       }
     }
   }
   ListCellRenderer renderer = combobox.getRenderer();
   if (renderer instanceof JLabel) {
     int baseline = y + getLabelBaseline((JLabel) renderer, height);
     if (isAqua()) {
       return baseline - 1;
     }
     return baseline;
   }
   // Renderer isn't a label, use metrics directly.
   FontMetrics fm = combobox.getFontMetrics(combobox.getFont());
   return y + fm.getAscent();
 }