当前位置: 首页>>代码示例>>Java>>正文


Java Border.getBorderInsets方法代码示例

本文整理汇总了Java中javax.swing.border.Border.getBorderInsets方法的典型用法代码示例。如果您正苦于以下问题:Java Border.getBorderInsets方法的具体用法?Java Border.getBorderInsets怎么用?Java Border.getBorderInsets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.border.Border的用法示例。


在下文中一共展示了Border.getBorderInsets方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getListCellRendererComponent

import javax.swing.border.Border; //导入方法依赖的package包/类
public Component getListCellRendererComponent(JList list, Object value,
    int index, boolean isSelected, boolean cellHasFocus) {
    setComponentOrientation(list.getComponentOrientation());
    if (isSelected) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());
    }
    else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }

    setEnabled(list.isEnabled());
    setFont(list.getFont());
    if( cellHasFocus ) {
        Border b = UIManager.getBorder("List.focusCellHighlightBorder"); //NOI18N
        if( null != b && null != b.getBorderInsets(this) )
            setBorder( b );
    } else {
        setBorder( noFocusBorder);
    }

    setText((value == null) ? "" : value.toString());
    setSelected(((CheckListModel) list.getModel()).isChecked(index));
    return this;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:DefaultCheckListCellRenderer.java

示例2: test

import javax.swing.border.Border; //导入方法依赖的package包/类
private static void test(Border border) {
    Insets actual = border.getBorderInsets(null);
    if (NEGATIVE.equals(actual)) {
        throw new Error("unexpected insets in " + border.getClass());
    }
    Insets expected = (Insets) actual.clone();
    // modify
    actual.top++;
    actual.left++;
    actual.right++;
    actual.bottom++;
    // validate
    if (!expected.equals(border.getBorderInsets(null))) {
        throw new Error("shared insets in " + border.getClass());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:Test6657026.java

示例3: getInsets

import javax.swing.border.Border; //导入方法依赖的package包/类
public @Override Insets getInsets(Insets insets) {
    Insets result;

    //Call getBorder(), not just read the field - if swingRendering, the border will be constructed, and the
    //insets are what will make the indent property work;  HtmlLabelUI doesn't need this, it just reads the
    //insets property, but BasicLabelUI and its ilk do
    Border b = getBorder();

    if (b == null) {
        result = EMPTY_INSETS;
    } else {
        //workaround for open jdk bug, see issue #192388
        try {
            result = b.getBorderInsets(this);
        } catch( NullPointerException e ) {
            Logger.getLogger(HtmlRendererImpl.class.getName()).log(Level.FINE, null, e);
            result = EMPTY_INSETS;
        }
    }
    if( null != insets ) {
        insets.set( result.top, result.left, result.bottom, result.right);
        return insets;
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:HtmlRendererImpl.java

示例4: getListCellRendererComponent

import javax.swing.border.Border; //导入方法依赖的package包/类
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    FormatInfo info = (FormatInfo)value;
    Component comp = delegate.getListCellRendererComponent(list, info.getDisplayName(), index, isSelected, cellHasFocus);
    if (comp instanceof JComponent) {
        JComponent jcomp = (JComponent)comp;
        Border border = jcomp.getBorder();
        if ((border != null) && (border.getBorderInsets(panel) != null)) { // Issue 161997
            panel.setBorder(border);
        } else {
            panel.setBorder(BorderFactory.createEmptyBorder());
        }
        panel.setOpaque(jcomp.isOpaque());
        jcomp.setBorder(null);
    }
    panel.removeAll();
    panel.setBackground(comp.getBackground());
    // 1st column            
    comp.setPreferredSize(null);
    Dimension prefSize = comp.getPreferredSize();
    comp.setPreferredSize(new Dimension(width1, prefSize.height));
    comp.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
    panel.add(comp);
    panel.add(Box.createHorizontalStrut(5));
    // 2nd column
    label.setText(info.getExample());
    label.setForeground(comp.getForeground());
    label.setFont(comp.getFont());
    label.setPreferredSize(null);
    prefSize = label.getPreferredSize();
    label.setPreferredSize(new Dimension(width2, prefSize.height));
    label.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
    panel.add(label);
    return panel;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:FormatSelector.java

示例5: getMinimumSize

import javax.swing.border.Border; //导入方法依赖的package包/类
@Override
public Dimension getMinimumSize() {
    if (!hasVisibleComponents()) {
        // have minimum size, to avoid gridbag layout to place the empty component at [0,0] location.
        // clashes with the dnd
        Border b = getBorder();
        if( null != b ) {
            Insets insets = b.getBorderInsets( this );
            return new Dimension( Math.max(1, insets.left+insets.right), Math.max(1, insets.top+insets.bottom) );
        }
        return new Dimension(1,1);
    }
    return super.getMinimumSize();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:SlideBarContainer.java

示例6: test

import javax.swing.border.Border; //导入方法依赖的package包/类
private static void test(Border border, Insets insets) {
    Insets result = border.getBorderInsets(getComponent(border));
    if (insets == result) {
        throw new Error("both instances are the same for " + border.getClass());
    }
    if (!insets.equals(result)) {
        throw new Error("both insets are not equal for " + border.getClass());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:Test4856008.java

示例7: getInsets

import javax.swing.border.Border; //导入方法依赖的package包/类
/**
 * If a border has been set on this component, returns the
 * border's insets, else calls super.getInsets.
 *
 * @return the value of the insets property.
 * @see #setBorder
 */
public Insets getInsets() {
    Border    border = getBorder();

    if (border != null) {
        return border.getBorderInsets(this);
    }
    return super.getInsets();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:BasicSplitPaneDivider.java

示例8: damage

import javax.swing.border.Border; //导入方法依赖的package包/类
/**
 * Damages the area surrounding the caret to cause
 * it to be repainted in a new location.  If paint()
 * is reimplemented, this method should also be
 * reimplemented.  This method should update the
 * caret bounds (x, y, width, and height).
 *
 * @param r  the current location of the caret
 * @see #paint
 */
protected synchronized void damage(final Rectangle r) {
    if (r == null || fPainting) return;

    x = r.x - 4;
    y = r.y;
    width = 10;
    height = r.height;

    // Don't damage the border area.  We can't paint a partial border, so get the
    // intersection of the caret rectangle and the component less the border, if any.
    final Rectangle caretRect = new Rectangle(x, y, width, height);
    final Border border = getComponent().getBorder();
    if (border != null) {
        final Rectangle alloc = getComponent().getBounds();
        alloc.x = alloc.y = 0;
        final Insets borderInsets = border.getBorderInsets(getComponent());
        alloc.x += borderInsets.left;
        alloc.y += borderInsets.top;
        alloc.width -= borderInsets.left + borderInsets.right;
        alloc.height -= borderInsets.top + borderInsets.bottom;
        Rectangle2D.intersect(caretRect, alloc, caretRect);
    }
    x = caretRect.x;
    y = caretRect.y;
    width = Math.max(caretRect.width, 1);
    height = Math.max(caretRect.height, 1);
    repaint();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:AquaCaret.java

示例9: main

import javax.swing.border.Border; //导入方法依赖的package包/类
public static void main(String[] args) {
    Component c = new Component() {};
    c.setBackground(Color.WHITE);
    c.setForeground(Color.BLACK);
    Graphics g = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_RGB).getGraphics();
    g.setClip(0, 0, 1024, 768);
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        border.getBorderInsets(c);
        border.paintBorder(c, g, 0, 0, 1024, 768);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:Test6978482.java

示例10: test

import javax.swing.border.Border; //导入方法依赖的package包/类
void test(String uiName) {
    Border b = UIManager.getBorder(uiName);
    Insets i = b.getBorderInsets(null);
    if (i == null) {
        throw new RuntimeException("getBorderInsets() returns null for " + uiName);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:Test6963870.java

示例11: damage

import javax.swing.border.Border; //导入方法依赖的package包/类
/**
 * Damages the area surrounding the caret to cause
 * it to be repainted in a new location.  If paint()
 * is reimplemented, this method should also be
 * reimplemented.  This method should update the
 * caret bounds (x, y, width, and height).
 *
 * @param r  the current location of the caret
 * @see #paint
 */
@Override
protected synchronized void damage(final Rectangle r) {
    if (r == null || fPainting) return;

    x = r.x - 4;
    y = r.y;
    width = 10;
    height = r.height;

    // Don't damage the border area.  We can't paint a partial border, so get the
    // intersection of the caret rectangle and the component less the border, if any.
    final Rectangle caretRect = new Rectangle(x, y, width, height);
    final Border border = getComponent().getBorder();
    if (border != null) {
        final Rectangle alloc = getComponent().getBounds();
        alloc.x = alloc.y = 0;
        final Insets borderInsets = border.getBorderInsets(getComponent());
        alloc.x += borderInsets.left;
        alloc.y += borderInsets.top;
        alloc.width -= borderInsets.left + borderInsets.right;
        alloc.height -= borderInsets.top + borderInsets.bottom;
        Rectangle2D.intersect(caretRect, alloc, caretRect);
    }
    x = caretRect.x;
    y = caretRect.y;
    width = Math.max(caretRect.width, 1);
    height = Math.max(caretRect.height, 1);
    repaint();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:AquaCaret.java

示例12: CollapsiblePanel

import javax.swing.border.Border; //导入方法依赖的package包/类
public CollapsiblePanel(VCSCommitPanel master, String sectionButtonText, boolean defaultSectionDisplayed) {
    this.master = master;
    ActionListener al = new ActionListener() {
       @Override
       public void actionPerformed(ActionEvent e) {
           if (sectionPanel.isVisible()) {
               hideSection();
           } else {
               displaySection();
           }
       }
    };

    this.sectionButton = new SectionButton(al);
    this.sectionPanel = new JPanel();

    this.sectionButton.setSelected(defaultSectionDisplayed);

    setLayout(new BoxLayout(this, Y_AXIS));
    Mnemonics.setLocalizedText(sectionButton, sectionButtonText);
    sectionButton.setMaximumSize(new Dimension(Integer.MAX_VALUE, sectionButton.getMaximumSize().height));
    add(sectionButton);
    add(master.makeVerticalStrut(sectionButton, sectionPanel, RELATED, master));
    add(sectionPanel);  

    setAlignmentX(LEFT_ALIGNMENT);
    sectionPanel.setLayout(new BoxLayout(sectionPanel, Y_AXIS));
    sectionPanel.setAlignmentX(LEFT_ALIGNMENT);            
    sectionButton.setAlignmentX(LEFT_ALIGNMENT);

    Icon i = sectionButton.getIcon();
    Border b = sectionButton.getBorder();
    int left = (b != null ? b.getBorderInsets(sectionButton).left : 0) + (i != null ? i.getIconWidth() : 16) + sectionButton.getIconTextGap();
    int bottom = master.getContainerGap(SOUTH);
    sectionPanel.setBorder(createEmptyBorder(0,     // top
                            left,                   // left
                            bottom,                 // bottom
                            0));                    // right

    if(defaultSectionDisplayed) {
        displaySection();
    } else {
        hideSection();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:46,代码来源:CollapsiblePanel.java

示例13: setBorder

import javax.swing.border.Border; //导入方法依赖的package包/类
public void setBorder(Border border) {
    this.border = border;
    if (border == null) borderInsets = EMPTY_INSETS;
    else borderInsets = new EnhancedInsets(border.getBorderInsets(this));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:6,代码来源:EnhancedLabelRenderer.java

示例14: createStrut

import javax.swing.border.Border; //导入方法依赖的package包/类
private static Component createStrut(JComponent c, int width, boolean before) {
    Border b = c.getBorder();
    Insets i = b != null ? b.getBorderInsets(c) : null;
    int w = i == null ? width : Math.max(width - (before ? i.left : i.right), 0);
    return Box.createHorizontalStrut(w);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:ObjectsFeatureModes.java

示例15: computePopupBounds

import javax.swing.border.Border; //导入方法依赖的package包/类
/**
 * Calculate the placement and size of the popup portion of the combo box based
 * on the combo box location and the enclosing screen bounds. If
 * no transformations are required, then the returned rectangle will
 * have the same values as the parameters.
 *
 * @param px starting x location
 * @param py starting y location
 * @param pw starting width
 * @param ph starting height
 * @return a rectangle which represents the placement and size of the popup
 */
protected Rectangle computePopupBounds(int px,int py,int pw,int ph) {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Rectangle screenBounds;

    // Calculate the desktop dimensions relative to the combo box.
    GraphicsConfiguration gc = comboBox.getGraphicsConfiguration();
    Point p = new Point();
    SwingUtilities.convertPointFromScreen(p, comboBox);
    if (gc != null) {
        Insets screenInsets = toolkit.getScreenInsets(gc);
        screenBounds = gc.getBounds();
        screenBounds.width -= (screenInsets.left + screenInsets.right);
        screenBounds.height -= (screenInsets.top + screenInsets.bottom);
        screenBounds.x += (p.x + screenInsets.left);
        screenBounds.y += (p.y + screenInsets.top);
    }
    else {
        screenBounds = new Rectangle(p, toolkit.getScreenSize());
    }
    int borderHeight = 0;
    Border popupBorder = getBorder();
    if (popupBorder != null) {
        Insets borderInsets = popupBorder.getBorderInsets(this);
        borderHeight = borderInsets.top + borderInsets.bottom;
        screenBounds.width -= (borderInsets.left + borderInsets.right);
        screenBounds.height -= borderHeight;
    }
    Rectangle rect = new Rectangle(px, py, pw, ph);
    if (py + ph > screenBounds.y + screenBounds.height) {
        if (ph <= -screenBounds.y - borderHeight) {
            // popup goes above
            rect.y = -ph - borderHeight;
        } else {
            // a full screen height popup
            rect.y = screenBounds.y + Math.max(0, (screenBounds.height - ph) / 2 );
            rect.height = Math.min(screenBounds.height, ph);
        }
    }
    return rect;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:53,代码来源:BasicComboPopup.java


注:本文中的javax.swing.border.Border.getBorderInsets方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。