javax.swing.border.Border类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中javax.swing.border.Border类的一些代码示例,展示了Border类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Border类的具体详情如下:
包路径:javax.swing.border.Border
类名称:Border

Border介绍

暂无

代码示例

代码示例来源:origin: libgdx/libgdx

@Override
public void run () {
  JPanel panel = new JPanel(new FlowLayout());
  JPanel textPanel = new JPanel() {
    public boolean isOptimizedDrawingEnabled () {
      return false;
  };
  textPanel.setLayout(new OverlayLayout(textPanel));
  panel.add(textPanel);
  placeholderLabel.setBorder(new EmptyBorder(border.getBorderInsets(textField)));

代码示例来源:origin: org.bitbucket.goalhub.simpleide/jedit

public Dimension getPreferredSize()
{
  int width = boldFM.stringWidth(path);
  int height = boldFM.getHeight();
  for(int i = 0; i < messages.length; i++)
  {
    width = Math.max(plainFM.stringWidth(messages[i]),width);
    height += plainFM.getHeight();
  }
  Insets insets = getBorder().getBorderInsets(this);
  width += insets.left + insets.right;
  height += insets.top + insets.bottom;
  return new Dimension(width,height);
} //}}}

代码示例来源:origin: stackoverflow.com

public void showFrame() {
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  this.setPreferredSize(new Dimension(500, 500));
  this.getContentPane().setBackground(Color.yellow);
  JPanel p = new JPanel();
  p.setPreferredSize(new Dimension(400, 400));
  p.setBackground(Color.red);
  Border border = BorderFactory.createLineBorder(Color.blue, 10);
  border.isBorderOpaque();
  p.setBorder(border);
  this.add(p, BorderLayout.NORTH);
  this.pack();
  this.setVisible(true);
}

public static void main(String[] args) {
  new DifferentColor().showFrame();
}

代码示例来源:origin: org.gosu-lang.gosu/gosu-lab

public synchronized Dimension getMinimumSize()
{
 if( _image == null )
 {
  return super.getMinimumSize();
 }
 Insets insets = _border == null ? new Insets( 0, 0, 0, 0 ) : _border.getBorderInsets( this );
 return _minDim == null ? new Dimension( _image.getIconWidth() + ((_border != null) ? (insets.left + insets.right) : 0),
                     _image.getIconHeight() + ((_border != null) ? (insets.top + insets.bottom) : 0) )
     : _minDim;
}

代码示例来源:origin: org.swinglabs.swingx/swingx-core

@Override protected void paintBackground(Graphics2D g, JXStatusBar bar) {        
  g.setColor(bar.getBackground());
  g.fillRect(0, 0, bar.getWidth(), bar.getHeight());
  
  //paint an inset border around each component. This suggests that
  //there is an extra border around the status bar...!
  Border b = BorderFactory.createBevelBorder(BevelBorder.LOWERED, 
      Color.WHITE, bar.getBackground(), bar.getBackground(), Color.GRAY);
  Insets insets = new Insets(0, 0, 0, 0);
  for (Component c : bar.getComponents()) {
    getSeparatorInsets(insets);
    int x = c.getX() - insets.right;
    int y = c.getY() - 2;
    int w = c.getWidth() + insets.left + insets.right;
    int h = c.getHeight() + 4;
    b.paintBorder(c, g, x, y, w, h);
  }
}

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-bu

public Insets getBorderInsets(Component _c)
{
 Insets r=border_.getBorderInsets(_c);
 return new Insets(top_    ? r.top    : 0,
          left_   ? r.left   : 0,
          bottom_ ? r.bottom : 0,
          right_  ? r.right  : 0);
}

代码示例来源:origin: org.bitbucket.goalhub.simpleide/jedit

public Dimension preferredLayoutSize(Container parent)
{
  Insets insets = ((JComponent)parent).getBorder()
    .getBorderInsets(parent);
  Component[] comp = parent.getComponents();
  if(comp.length <= 2)
  {
    // nothing 'cept close box
    return new Dimension(0,0);
  }
  Dimension dim = comp[2].getPreferredSize();
  if(position.equals(DockableWindowManagerImpl.TOP)
    || position.equals(DockableWindowManagerImpl.BOTTOM))
  {
    int width = parent.getWidth() - insets.right;
    Dimension returnValue = preferredLayoutSizeLR(insets, comp, dim, width);
    return returnValue;
  }
  else
  {
    Dimension returnValue = preferredLayoutSizeTB(parent.getHeight(), insets, comp, dim);
    return returnValue;
  }
} //}}}

代码示例来源:origin: de.rototor.jeuclid/jeuclid-core

private Dimension calculatePreferredSize(final JComponent c,
    JEuclidView jEuclidView) {
  Dimension retVal;
  retVal = new Dimension((int) Math.ceil(jEuclidView.getWidth()),
      (int) Math.ceil(jEuclidView.getAscentHeight()
          + jEuclidView.getDescentHeight()));
  final Border border = c.getBorder();
  if (border != null) {
    final Insets insets = border.getBorderInsets(c);
    if (insets != null) {
      retVal.width += insets.left + insets.right;
      retVal.height += insets.top + insets.bottom;
    }
  }
  return retVal;
}

代码示例来源:origin: org.activecomponents.jadex/jadex-commons-gui

public Dimension getPreferredSize()
  {
    // Try to use dimension from containing scroll panel to expand to full size.
    Dimension    pref    = super.getPreferredSize();
    
    Dimension    par    = null;
    if(getParent()!=null && getParent().getParent() instanceof JScrollPane)
    {
      JScrollPane    scroll    = (JScrollPane)getParent().getParent();
      par    = scroll.getSize();
      Border    border    = scroll.getBorder();
      if(border!=null)
      {
        Insets    insets    = scroll.getBorder().getBorderInsets(scroll);
        par.width    -= insets.left + insets.right;
        par.height    -= insets.top + insets.bottom;
      }
    }
//        System.out.println("par: "+par);
    int	prefwidth	= pref!=null ? pref.width : 0;
    int	prefheight	= pref!=null ? pref.height : 0;
    int	parwidth	= par!=null ? par.width : 0;
    int	parheight	= par!=null ? par.height : 0;
    Dimension    ret    = new Dimension(Math.max(prefwidth, parwidth), Math.max(prefheight, parheight));
    return ret;
  }

代码示例来源:origin: org.databene/databene-commons

public static void equalizeButtonSizes(Graphics g, JButton... buttons) {
  String[] labels = BeanUtil.extractProperties(buttons, "text", String.class);
  // Get the largest width and height
  Dimension maxSize = new Dimension(0, 0);
  Rectangle2D textBounds = null;
  JButton button0 = buttons[0];
  FontMetrics metrics = button0.getFontMetrics(button0.getFont());
  for (int i = 0; i < labels.length; ++i) {
    textBounds = metrics.getStringBounds(labels[i], g);
    maxSize.width = Math.max(maxSize.width, (int) textBounds.getWidth());
    maxSize.height = Math.max(maxSize.height, (int) textBounds.getHeight());
  }
  Insets insets = button0.getBorder().getBorderInsets(button0);
  maxSize.width += insets.left + insets.right;
  maxSize.height += insets.top + insets.bottom;
  // reset preferred and maximum size since BoxLayout takes both into account
  for (JButton button : buttons) {
    button.setPreferredSize((Dimension) maxSize.clone());
    button.setMaximumSize((Dimension) maxSize.clone());
  }
}

代码示例来源:origin: org.bitbucket.goalhub.simpleide/jedit

private Insets getInsets(Component parent)
{
  Border border = ((JComponent)parent).getBorder();
  if(border == null)
    return new Insets(0,0,0,0);
  else
    return border.getBorderInsets(parent);
} //}}}

代码示例来源:origin: org.netbeans.modules/org-netbeans-lib-profiler-ui

public void setBorder(Border border) {
  super.setBorder(border);
  originalBorder = border;
  if (originalBorder != null) {
    originalBorderInsets = originalBorder.getBorderInsets(this);
  }
}

代码示例来源:origin: net.java.dev.laf-widget/laf-widget

public Insets getBorderInsets(Component c) {
  LafWidgetSupport lafSupport = LafWidgetRepository.getRepository()
      .getLafSupport();
  Icon lockIcon = lafSupport.getLockIcon(c);
  if (lockIcon == null)
    lockIcon = LafWidgetUtilities.getSmallLockIcon();
  Insets origInsets = this.originalBorder.getBorderInsets(c);
  if (c.getComponentOrientation().isLeftToRight()) {
    return new Insets(origInsets.top, Math.max(origInsets.left,
        lockIcon.getIconWidth() + 2), origInsets.bottom,
        origInsets.right);
  } else {
    // support for RTL
    return new Insets(origInsets.top, origInsets.left,
        origInsets.bottom, Math.max(origInsets.right, lockIcon
            .getIconWidth() + 2));
  }
}

代码示例来源:origin: ru.sbtqa/monte-media

@Override
public void paint(Graphics g, JComponent c) {
  g.setColor(c.getBackground());
  g.fillRect(0, 0, c.getWidth(), c.getHeight());
  ButtonModel m = ((AbstractButton) c).getModel();
  /*
  PlafUtils.paintBevel(c, g, 0, 0, c.getWidth(), c.getHeight(), true /*m.isEnabled()* /, m.isPressed() & m.isArmed(), m.isSelected());
   */
  Border b = c.getBorder();
  if (b instanceof BackdropBorder) {
    ((BackdropBorder) b).getBackgroundBorder().paintBorder(c, g, 0, 0, c.getWidth(), c.getHeight());
  }
  super.paint(g, c);
}

代码示例来源:origin: igniterealtime/Spark

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  Insets borderInsets = border.getBorderInsets(c);
  Insets insets = getBorderInsets(c);
  int temp = (insets.top - borderInsets.top) / 2;
  border.paintBorder(c, g, x, y + temp, width, height - temp);
  Dimension size = comp.getPreferredSize();
  rect = new Rectangle(offset, 0, size.width, size.height);
  SwingUtilities.paintComponent(g, comp, (Container)c, rect);
}

代码示例来源:origin: org.bitbucket.goalhub.simpleide/jedit

/**
 * Returns the width or height of wrapped rows or columns.
 */
int getWrappedDimension(JComponent parent, int dimension)
{
  Insets insets = parent.getBorder()
    .getBorderInsets(parent);
  Component[] comp = parent.getComponents();
  if(comp.length <= 2)
    return 0;
  Dimension dim = comp[2].getPreferredSize();
  if(position.equals(DockableWindowManagerImpl.TOP)
    || position.equals(DockableWindowManagerImpl.BOTTOM))
  {
    int width = dimension - insets.right;
    Dimension returnValue = preferredLayoutSizeLR(insets, comp, dim, width);
    return returnValue.height;
  }
  else
  {
    Dimension returnValue = preferredLayoutSizeTB(dimension, insets, comp, dim);
    return returnValue.width;
  }
} //}}}

代码示例来源:origin: net.sourceforge.mydoggy/mydoggy-plaf

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  switch (anchor) {
    case LEFT:
      border.paintBorder(c, g, x + c.getWidth() - 5, y, 5, height);
      break;
    case RIGHT:
      border.paintBorder(c, g, x, y, 5, height);
      break;
    case TOP:
      border.paintBorder(c, g, x, y + c.getHeight() - 5, width, 5);
      break;
    case BOTTOM:
      border.paintBorder(c, g, x, y, width, 5);
      break;
  }
}

代码示例来源:origin: igniterealtime/Spark

public Insets getBorderInsets(Component c) {
  Dimension size = comp.getPreferredSize();
  Insets insets = border.getBorderInsets(c);
  insets.top = Math.max(insets.top, size.height);
  return insets;
}

代码示例来源:origin: net.java.abeille/abeille

/**
 * Renders the border using the current look and feel.
 * 
 * @param g
 *            the <code>Graphics</code> context in which to paint
 * @param c
 *            the component being painted;
 */
public void paint(Graphics g, JComponent c) {
  Border border = UIManager.getBorder("TitledBorder.border");
  if (c instanceof TitledBorderBottom && border != null) {
    /**
     * render the border at a negative x-offset and y-offset (4 pixels)
     * so that the top of the rectangle is clipped by the component
     */
    border.paintBorder(c, g, -4, -4, c.getWidth() + 8, c.getHeight() + 4);
  }
}

代码示例来源:origin: com.jidesoft/jide-oss

protected void resizeEditor(int tabIndex) {
    // note - this should use the logic of label paint text so that the text overlays exactly.
    Rectangle tabsTextBoundsAt = getTabsTextBoundsAt(tabIndex);
    if (tabsTextBoundsAt.isEmpty()) {
      tabsTextBoundsAt = new Rectangle(14, 3); // note - 14 should be the font height but...
    }

    tabsTextBoundsAt.x = tabsTextBoundsAt.x - _tabEditor.getBorder().getBorderInsets(_tabEditor).left;
    tabsTextBoundsAt.width = +tabsTextBoundsAt.width +
        _tabEditor.getBorder().getBorderInsets(_tabEditor).left +
        _tabEditor.getBorder().getBorderInsets(_tabEditor).right;
    tabsTextBoundsAt.y = tabsTextBoundsAt.y - _tabEditor.getBorder().getBorderInsets(_tabEditor).top;
    tabsTextBoundsAt.height = tabsTextBoundsAt.height +
        _tabEditor.getBorder().getBorderInsets(_tabEditor).top +
        _tabEditor.getBorder().getBorderInsets(_tabEditor).bottom;
    _tabEditor.setBounds(SwingUtilities.convertRectangle(_tabPane, tabsTextBoundsAt, getTabPanel()));
    _tabEditor.invalidate();
    _tabEditor.validate();

//        getTabPanel().invalidate();
//        getTabPanel().validate();
//        getTabPanel().repaint();
//        getTabPanel().doLayout();

    _tabPane.doLayout();

    // mtf - note - this is an exteme repaint but we need to paint any content borders
    getTabPanel().getParent().getParent().repaint();
  }

相关文章