コード例 #1
0
  @SuppressWarnings("unchecked")
  static <C extends JComponent & BackgroundPaintable> void paintBackground(C comp, Graphics2D g) {
    // we should be painting the background behind the painter if we have one
    // this prevents issues with buffer reuse where visual artifacts sneak in
    if (comp.isOpaque()
        || (comp instanceof AlphaPaintable && ((AlphaPaintable) comp).getAlpha() < 1f)
        || UIManager.getLookAndFeel().getID().equals("Nimbus")) {
      g.setColor(comp.getBackground());
      g.fillRect(0, 0, comp.getWidth(), comp.getHeight());
    }

    Painter<? super C> painter = comp.getBackgroundPainter();

    if (painter != null) {
      if (comp.isPaintBorderInsets()) {
        painter.paint(g, comp, comp.getWidth(), comp.getHeight());
      } else {
        Insets insets = comp.getInsets();
        g.translate(insets.left, insets.top);
        painter.paint(
            g,
            comp,
            comp.getWidth() - insets.left - insets.right,
            comp.getHeight() - insets.top - insets.bottom);
        g.translate(-insets.left, -insets.top);
      }
    }
  }
コード例 #2
0
ファイル: DockingUtils.java プロジェクト: metsci/glimpse
 public static <C extends Component> C findLargestComponent(Collection<C> components) {
   int largestArea = -1;
   C largestComponent = null;
   for (C c : components) {
     int area = c.getWidth() * c.getHeight();
     if (area > largestArea) {
       largestComponent = c;
       largestArea = area;
     }
   }
   return largestComponent;
 }