Java Code Examples for java.awt.Insets

The following examples show how to use java.awt.Insets. These examples are extracted from open source projects.
Example 1
Project: javamoney-examples   File: PasswordDialog.java    License: Apache License 2.0 6 votes vote down vote up
private
Panel
createPasswordPanel()
{
  Panel panel = new Panel();
  String gap = ": ";

  // Build panel.
  panel.setAnchor(GridBagConstraints.EAST);
  panel.add(getSharedProperty("password") + gap, 0, 0, 1, 1, 0, 50);
  panel.add(getProperty("retype") + gap, 0, 1, 1, 1, 0, 50);

  panel.setFill(GridBagConstraints.HORIZONTAL);
  panel.add(getFields()[PASSWORD], 1, 0, 1, 1, 100, 0);
  panel.add(getFields()[PASSWORD_CONFIRM], 1, 1, 1, 1, 0, 0);

  panel.setInsets(new Insets(10, 10, 10, 150));

  return panel;
}
 
Example 2
Project: openjdk-jdk8u-backup   File: GroupLayout.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Lays out the specified container.
 *
 * @param parent the container to be laid out
 * @throws IllegalStateException if any of the components added to
 *         this layout are not in both a horizontal and vertical group
 */
public void layoutContainer(Container parent) {
    // Step 1: Prepare for layout.
    prepare(SPECIFIC_SIZE);
    Insets insets = parent.getInsets();
    int width = parent.getWidth() - insets.left - insets.right;
    int height = parent.getHeight() - insets.top - insets.bottom;
    boolean ltr = isLeftToRight();
    if (getAutoCreateGaps() || getAutoCreateContainerGaps() ||
            hasPreferredPaddingSprings) {
        // Step 2: Calculate autopadding springs
        calculateAutopadding(horizontalGroup, HORIZONTAL, SPECIFIC_SIZE, 0,
                width);
        calculateAutopadding(verticalGroup, VERTICAL, SPECIFIC_SIZE, 0,
                height);
    }
    // Step 3: set the size of the groups.
    horizontalGroup.setSize(HORIZONTAL, 0, width);
    verticalGroup.setSize(VERTICAL, 0, height);
    // Step 4: apply the size to the components.
    for (ComponentInfo info : componentInfos.values()) {
        info.setBounds(insets, width, ltr);
    }
}
 
Example 3
Project: openjdk-8   File: ScrollPaneLayout.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adjusts the <code>Rectangle</code> <code>available</code> based on if
 * the horizontal scrollbar is needed (<code>wantsHSB</code>).
 * The location of the hsb is updated in <code>hsbR</code>, and
 * the viewport border insets (<code>vpbInsets</code>) are used to offset
 * the hsb.  This is only called when <code>wantsHSB</code> has
 * changed, eg you shouldn't invoked adjustForHSB(true) twice.
 */
private void adjustForHSB(boolean wantsHSB, Rectangle available,
                          Rectangle hsbR, Insets vpbInsets) {
    int oldHeight = hsbR.height;
    if (wantsHSB) {
        int hsbHeight = Math.max(0, Math.min(available.height,
                                          hsb.getPreferredSize().height));

        available.height -= hsbHeight;
        hsbR.y = available.y + available.height + vpbInsets.bottom;
        hsbR.height = hsbHeight;
    }
    else {
        available.height += oldHeight;
    }
}
 
Example 4
Project: TencentKona-8   File: GroupLayout.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Lays out the specified container.
 *
 * @param parent the container to be laid out
 * @throws IllegalStateException if any of the components added to
 *         this layout are not in both a horizontal and vertical group
 */
public void layoutContainer(Container parent) {
    // Step 1: Prepare for layout.
    prepare(SPECIFIC_SIZE);
    Insets insets = parent.getInsets();
    int width = parent.getWidth() - insets.left - insets.right;
    int height = parent.getHeight() - insets.top - insets.bottom;
    boolean ltr = isLeftToRight();
    if (getAutoCreateGaps() || getAutoCreateContainerGaps() ||
            hasPreferredPaddingSprings) {
        // Step 2: Calculate autopadding springs
        calculateAutopadding(horizontalGroup, HORIZONTAL, SPECIFIC_SIZE, 0,
                width);
        calculateAutopadding(verticalGroup, VERTICAL, SPECIFIC_SIZE, 0,
                height);
    }
    // Step 3: set the size of the groups.
    horizontalGroup.setSize(HORIZONTAL, 0, width);
    verticalGroup.setSize(VERTICAL, 0, height);
    // Step 4: apply the size to the components.
    for (ComponentInfo info : componentInfos.values()) {
        info.setBounds(insets, width, ltr);
    }
}
 
Example 5
Project: TencentKona-8   File: BasicLabelUI.java    License: GNU General Public License v2.0 6 votes vote down vote up
private String layout(JLabel label, FontMetrics fm,
                      int width, int height) {
    Insets insets = label.getInsets(null);
    String text = label.getText();
    Icon icon = (label.isEnabled()) ? label.getIcon() :
                                      label.getDisabledIcon();
    Rectangle paintViewR = new Rectangle();
    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;
    return layoutCL(label, fm, text, icon, paintViewR, paintIconR,
                    paintTextR);
}
 
Example 6
Project: openAGV   File: DrawingViewPlacardPanel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a button to toglle the labels.
 *
 * @param view The DrawingView the button will belong to.
 * @return The created button.
 */
private JToggleButton toggleLabelsButton(final OpenTCSDrawingView drawingView) {
  final JToggleButton toggleButton = new JToggleButton();

  toggleButton.setToolTipText(
      labels.getString("drawingViewPlacardPanel.button_toggleLabels.tooltipText")
  );

  toggleButton.setIcon(ImageDirectory.getImageIcon("/menu/comment-add.16.png"));

  toggleButton.setMargin(new Insets(0, 0, 0, 0));
  toggleButton.setFocusable(false);

  toggleButton.addItemListener(
      (ItemEvent event) -> drawingView.setLabelsVisible(toggleButton.isSelected())
  );

  return toggleButton;
}
 
Example 7
Project: workcraft   File: MultiBorderLayout.java    License: MIT License 6 votes vote down vote up
private Dimension layoutSize(final Container target, final DimensionGetter getter) {
    synchronized (target.getTreeLock()) {
        final Dimension northSize = sumHorizontal(northList, getter);
        final Dimension southSize = sumHorizontal(southList, getter);
        final Dimension westSize = sumVertical(westList, getter);
        final Dimension eastSize = sumVertical(eastList, getter);
        final Dimension centerSize = sumCenter(centerList, getter);

        final Dimension dim = new Dimension(
                max(northSize.width, southSize.width, westSize.width + centerSize.width + eastSize.width),
                northSize.height + max(westSize.height, centerSize.height, eastSize.height) + southSize.height);

        final Insets insets = target.getInsets();
        dim.width += insets.left + insets.right;
        dim.height += insets.top + insets.bottom;
        return dim;
    }
}
 
Example 8
Project: xyTalk-pc   File: VerticalFlowLayout.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Returns the preferred dimensions given the components
 * in the target container.
 *
 * @param target the component to lay out
 */
public Dimension preferredLayoutSize(Container target) {
    Dimension tarsiz = new Dimension(0, 0);

    for (int i = 0; i < target.getComponentCount(); i++) {
        Component m = target.getComponent(i);
        if (m.isVisible()) {
            Dimension d = m.getPreferredSize();
            tarsiz.width = Math.max(tarsiz.width, d.width);
            if (i > 0) {
                tarsiz.height += hgap;
            }
            tarsiz.height += d.height;
        }
    }
    Insets insets = target.getInsets();
    tarsiz.width += insets.left + insets.right + hgap * target.getComponentCount();
    tarsiz.height += insets.top + insets.bottom + vgap * target.getComponentCount();
    return tarsiz;
}
 
Example 9
Project: FlatLaf   File: FlatPopupFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void show() {
	if( dropShadowDelegate != null )
		dropShadowDelegate.show();

	if( mediumWeightPanel != null )
		showMediumWeightDropShadow();

	super.show();

	// fix location of light weight popup in case it has left or top drop shadow
	if( lightComp != null ) {
		Insets insets = lightComp.getInsets();
		if( insets.left != 0 || insets.top != 0 )
			lightComp.setLocation( lightComp.getX() - insets.left, lightComp.getY() - insets.top );
	}
}
 
Example 10
Project: visualvm   File: MultiSplitContainer.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void mousePressed(MouseEvent e) {
    if (inDivider) {
        canDrag = true;
        dragX = e.getX();
        offsetX = dragX - dividerOffsets.get(offsetIdx);
        
        Insets insets = getInsets();
        minX = offsetIdx == 0 ? insets.left : dividerOffsets.get(offsetIdx - 1) + DIVIDER_SIZE;
        maxX = offsetIdx == dividerOffsets.size() - 1 ? getWidth() - insets.right - DIVIDER_SIZE :
                                                        dividerOffsets.get(offsetIdx + 1) - DIVIDER_SIZE;
        
        c1 = visibleComponents.get(offsetIdx);
        c2 = visibleComponents.get(offsetIdx + 1);
        relWidth = componentsWeights.get(c1) + componentsWeights.get(c2);
    }
}
 
Example 11
Project: gcs   File: CharacterSheetLayout.java    License: Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void layoutContainer(Container target) {
    Component[] children = target.getComponents();
    if (children.length > 0) {
        Dimension size   = children[0].getPreferredSize();
        Dimension avail  = target.getSize();
        Insets    insets = target.getInsets();
        int       x      = insets.left;
        int       y      = insets.top;
        int       margin = mSheet.getScale().scale(MARGIN);
        for (Component child : children) {
            child.setBounds(x, y, size.width, size.height);
            x += size.width + margin;
            if (x + size.width + insets.right > avail.width) {
                x = insets.left;
                y += size.height + margin;
            }
        }
    }
}
 
Example 12
Project: openjdk-jdk8u-backup   File: MotifBorders.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reinitialize the insets parameter with this Border's current Insets.
 * @param c the component for which this border insets value applies
 * @param insets the object to be reinitialized
 */
public Insets getBorderInsets(Component c, Insets insets) {
    if (!(c instanceof JPopupMenu)) {
        return insets;
    }
    FontMetrics fm;
    int         descent = 0;
    int         ascent = 16;

    String title = ((JPopupMenu)c).getLabel();
    if (title == null) {
        insets.left = insets.top = insets.right = insets.bottom = 0;
        return insets;
    }

    fm = c.getFontMetrics(font);

    if(fm != null) {
        descent = fm.getDescent();
        ascent = fm.getAscent();
    }

    insets.top += ascent + descent + TEXT_SPACING + GROOVE_HEIGHT;
    return insets;
}
 
Example 13
Project: LGoodDatePicker   File: InternalUtilities.java    License: MIT License 6 votes vote down vote up
/**
 * getScreenWorkingArea, This returns the working area of the screen. (The working area excludes
 * any task bars.) This function accounts for multi-monitor setups. If a window is supplied,
 * then the the monitor that contains the window will be used. If a window is not supplied, then
 * the primary monitor will be used.
 */
static public Rectangle getScreenWorkingArea(Window windowOrNull) {
    Insets insets;
    Rectangle bounds;
    if (windowOrNull == null) {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        insets = Toolkit.getDefaultToolkit().getScreenInsets(ge.getDefaultScreenDevice()
            .getDefaultConfiguration());
        bounds = ge.getDefaultScreenDevice().getDefaultConfiguration().getBounds();
    } else {
        GraphicsConfiguration gc = windowOrNull.getGraphicsConfiguration();
        insets = windowOrNull.getToolkit().getScreenInsets(gc);
        bounds = gc.getBounds();
    }
    bounds.x += insets.left;
    bounds.y += insets.top;
    bounds.width -= (insets.left + insets.right);
    bounds.height -= (insets.top + insets.bottom);
    return bounds;
}
 
Example 14
Project: hottub   File: MotifBorders.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reinitialize the insets parameter with this Border's current Insets.
 * @param c the component for which this border insets value applies
 * @param insets the object to be reinitialized
 */
public Insets getBorderInsets(Component c, Insets insets) {
    if (!(c instanceof JPopupMenu)) {
        return insets;
    }
    FontMetrics fm;
    int         descent = 0;
    int         ascent = 16;

    String title = ((JPopupMenu)c).getLabel();
    if (title == null) {
        insets.left = insets.top = insets.right = insets.bottom = 0;
        return insets;
    }

    fm = c.getFontMetrics(font);

    if(fm != null) {
        descent = fm.getDescent();
        ascent = fm.getAscent();
    }

    insets.top += ascent + descent + TEXT_SPACING + GROOVE_HEIGHT;
    return insets;
}
 
Example 15
Project: microba   File: MarkerBarUI.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void calculateViewRectAndBaseline(MarkerBar bar) {
	Insets insets = bar.getInsets();
	viewRect.x = insets.left;
	viewRect.y = insets.top;
	viewRect.width = bar.getWidth() - (insets.right + viewRect.x);
	viewRect.height = bar.getHeight() - (insets.bottom + viewRect.y);

	if (bar.getOrientation() == SwingConstants.HORIZONTAL) {
		baselineLeft = viewRect.x + MARKER_BODY_WIDTH / 2;
		baselineLength = viewRect.width - MARKER_BODY_WIDTH - 1;
		if (bar.isFliped()) {
			baselineTop = viewRect.y;
		} else {
			baselineTop = viewRect.y + viewRect.height - 1;
		}
	} else {
		baselineLeft = viewRect.y + MARKER_BODY_WIDTH / 2;
		baselineLength = viewRect.height - MARKER_BODY_WIDTH - 1;
		if (bar.isFliped()) {
			baselineTop = viewRect.x + viewRect.width - 1;
		} else {
			baselineTop = viewRect.x;
		}
	}
}
 
Example 16
Project: pumpernickel   File: ColorWellUI.java    License: MIT License 6 votes vote down vote up
@Override
public void paint(Graphics g0, JComponent c) {
	Graphics2D g = (Graphics2D) g0;
	JColorWell well = (JColorWell) c;
	Color color = well.getColorSelectionModel().getSelectedColor();
	Border border = c.getBorder();
	Insets borderInsets = border.getBorderInsets(c);
	if (color.getAlpha() < 255) {
		TexturePaint checkers = PlafPaintUtils.getCheckerBoard(8);
		g.setPaint(checkers);
		g.fillRect(borderInsets.left, borderInsets.top, c.getWidth()
				- borderInsets.left - borderInsets.right, c.getHeight()
				- borderInsets.top - borderInsets.bottom);
	}
	g.setColor(color);
	g.fillRect(borderInsets.left, borderInsets.top, c.getWidth()
			- borderInsets.left - borderInsets.right, c.getHeight()
			- borderInsets.top - borderInsets.bottom);
}
 
Example 17
Project: openjdk-jdk9   File: MatteBorder.java    License: GNU General Public License v2.0 6 votes vote down vote up
private Insets computeInsets(Insets insets) {
    if (tileIcon != null && top == -1 && bottom == -1 &&
        left == -1 && right == -1) {
        int w = tileIcon.getIconWidth();
        int h = tileIcon.getIconHeight();
        insets.top = h;
        insets.right = w;
        insets.bottom = h;
        insets.left = w;
    } else {
        insets.left = left;
        insets.top = top;
        insets.right = right;
        insets.bottom = bottom;
    }
    return insets;
}
 
Example 18
Project: openjdk-8   File: MetalBorders.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Insets getBorderInsets(Component c, Insets insets) {
    Insets margin = null;

    if (c instanceof AbstractButton) {
        margin = ((AbstractButton)c).getMargin();
    }
    if (margin == null || margin instanceof UIResource) {
        // default margin so replace
        insets.left = left;
        insets.top = top;
        insets.right = right;
        insets.bottom = bottom;
    } else {
        // Margin which has been explicitly set by the user.
        insets.left = margin.left;
        insets.top = margin.top;
        insets.right = margin.right;
        insets.bottom = margin.bottom;
    }
    return insets;
}
 
Example 19
Project: netbeans   File: JavaTestCreatorConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adds a border and a title around a given component.
 * If the component already has some border, it is overridden (not kept).
 *
 * @param  component  component the border and title should be added to
 * @param  insets  insets between the component and the titled border
 * @param  title  text of the title
 */
private static void addTitledBorder(JComponent component,
                                    Insets insets,
                                    String title) {
    Border insideBorder = BorderFactory.createEmptyBorder(
            insets.top, insets.left, insets.bottom, insets.right);
    Border outsideBorder = new TitledBorder(
            BorderFactory.createEtchedBorder(), title);
    component.setBorder(new CompoundBorder(outsideBorder, insideBorder));
}
 
Example 20
Project: jdk8u-jdk   File: CompactLayout.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Dimension getSize(Container parent, boolean minimum) {
    int n = parent.getComponentCount();
    Insets insets = parent.getInsets();
    Dimension d = new Dimension();
    for (int i = 0; i < n; i++) {
        Component comp = parent.getComponent(i);
        if (comp instanceof EnableButton) {
            continue;
        }
        Dimension p = (minimum
                       ? comp.getMinimumSize()
                       : comp.getPreferredSize());
        if (horizontal) {
            d.width += p.width;
            if (d.height < p.height) {
                d.height = p.height;
            }
        } else {
            if (d.width < p.width) {
                d.width = p.width;
            }
            d.height += p.height;
        }
    }
    d.width += (insets.left + insets.right);
    d.height += (insets.top + insets.bottom);
    return d;
}
 
Example 21
Project: jdk1.8-source-analysis   File: MetalBorders.java    License: Apache License 2.0 5 votes vote down vote up
public Insets getBorderInsets(Component c, Insets newInsets) {
    if (MetalLookAndFeel.usingOcean()) {
        newInsets.set(1, 2, 3, 2);
    }
    else {
        newInsets.top = newInsets.left = newInsets.bottom = newInsets.right = 2;
    }

    if (!(c instanceof JToolBar)) {
        return newInsets;
    }
    if ( ((JToolBar) c).isFloatable() ) {
        if ( ((JToolBar) c).getOrientation() == HORIZONTAL ) {
            if (c.getComponentOrientation().isLeftToRight()) {
                newInsets.left = 16;
            } else {
                newInsets.right = 16;
            }
        } else {// vertical
            newInsets.top = 16;
        }
    }

    Insets margin = ((JToolBar) c).getMargin();

    if ( margin != null ) {
        newInsets.left   += margin.left;
        newInsets.top    += margin.top;
        newInsets.right  += margin.right;
        newInsets.bottom += margin.bottom;
    }

    return newInsets;
}
 
Example 22
Project: triplea   File: PropertiesUi.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void init() {
  setLayout(new GridBagLayout());
  // Create a blank label to use as a vertical fill so that the label/item pairs are aligned to
  // the top of the panel
  // and are not grouped in the center if the parent component is taller than the preferred size
  // of the panel.
  final GridBagConstraints constraints = new GridBagConstraints();
  constraints.gridx = 0;
  constraints.gridy = 99;
  constraints.insets = new Insets(10, 0, 0, 0);
  constraints.weighty = 1.0;
  constraints.fill = GridBagConstraints.VERTICAL;
  final JLabel verticalFillLabel = new JLabel();
  add(verticalFillLabel, constraints);
}
 
Example 23
Project: stendhal   File: MemberCellRenderer.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList<? extends Member> list,
		Member member, int index, boolean isSelected, boolean cellHasFocus) {
	label.setText(member.getName());
	if (member.isLeader()) {
		label.setFont(boldFont);
	} else {
		label.setFont(normalFont);
	}

	/*
	 * This is very, very ugly. JList does not resize the component
	 * normally, so the StatusDisplayBar never gets the chance to update
	 * the model. Try to figure out the correct width.
	 */
	Insets insets = hpBar.getInsets();
	int barWidth = list.getWidth() - insets.left - insets.right - 2;
	insets = list.getInsets();
	barWidth -= insets.left + insets.right;
	hpBar.getModel().setMaxRepresentation(barWidth);

	if (member.isPresent()) {
		hpBar.setPresent(true);
		hpBar.setRatio(member.getHpRatio());
	} else {
		hpBar.setPresent(false);
	}

	return renderer;
}
 
Example 24
Project: jdk8u-jdk   File: EmptyBorder.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reinitialize the insets parameter with this Border's current Insets.
 * @param c the component for which this border insets value applies
 * @param insets the object to be reinitialized
 */
public Insets getBorderInsets(Component c, Insets insets) {
    insets.left = left;
    insets.top = top;
    insets.right = right;
    insets.bottom = bottom;
    return insets;
}
 
Example 25
Project: Spark   File: CallPanelButton.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Decorates the button with the approriate UI configurations.
 */
private void decorate() {
    setBorderPainted(false);
    setOpaque(true);

    setContentAreaFilled(false);
    setMargin(new Insets(0, 0, 0, 0));
}
 
Example 26
Project: rapidminer-studio   File: ProgressBarBorder.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Insets getBorderInsets(Component c) {
	boolean compressed = Boolean.parseBoolean(String.valueOf(((JProgressBar) c)
			.getClientProperty(RapidLookTools.PROPERTY_PROGRESSBAR_COMPRESSED)));
	if (compressed) {
		return new Insets(3, 3, 3, 3);

	} else {
		return new Insets(0, 3, 10, 3);
	}
}
 
Example 27
Project: TencentKona-8   File: ToolBarSeparatorPainter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected PaintContext getPaintContext() {
    //the paint context returned will have a few dummy values. The
    //implementation of doPaint doesn't bother with the "decode" methods
    //but calculates where to paint the circles manually. As such, we
    //only need to indicate in our PaintContext that we don't want this
    //to ever be cached
    return new PaintContext(
            new Insets(1, 0, 1, 0),
            new Dimension(38, 7),
            false, CacheMode.NO_CACHING, 1, 1);
}
 
Example 28
Project: javamoney-examples   File: SplitDialog.java    License: Apache License 2.0 5 votes vote down vote up
private
Panel
createDetailsPanel()
{
  Panel panel = new Panel();
  Panel details = new Panel();
  String gap = ": ";

  // Build details panel.
  details.setAnchor(GridBagConstraints.EAST);
  details.add(getProperty("sum") + gap, 0, 0, 1, 1, 0, 33);
  details.add(getProperty("unassigned") + gap, 0, 1, 1, 1, 0, 33);
  details.add(getProperty("total") + gap, 0, 2, 1, 1, 0, 34);

  details.setAnchor(GridBagConstraints.WEST);

  for(int len = 0; len < getLabels().length; ++len)
  {
    details.add(getLabels()[len], 1, len, 1, 1, 100, 0);
  }

  details.setBorder(createTitledBorder(getProperty("details")));

  // Build panel.
  panel.setFill(GridBagConstraints.BOTH);
  panel.add(details, 0, 0, 1, 1, 100, 100);

  panel.setInsets(new Insets(0, 15, 0, 15));

  return panel;
}
 
Example 29
Project: bigtable-sql   File: ConnectionPropertiesPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void addSqlTextAreaPanel(final GridBagConstraints gbc)
{
	gbc.weighty = .7;
	gbc.fill = GridBagConstraints.BOTH;
	gbc.insets = new Insets(10, 25, 10, 10);
	JPanel textPanel = new JPanel();
	textPanel.setLayout(new BorderLayout());
	textPanel.add(sqlTextArea, BorderLayout.CENTER);
	add(textPanel, gbc);
}
 
Example 30
Project: jdk8u60   File: EnableButton.java    License: GNU General Public License v2.0 5 votes vote down vote up
public EnableButton(Group group, int type) {
    super(icons[type]);
    this.group = group;
    this.type = type;
    addActionListener(this);
    setMargin(new Insets(0, 0, 0, 0));
    setBorderPainted(false);
}
 
Example 31
Project: HubPlayer   File: ButtonToolBar.java    License: GNU General Public License v3.0 5 votes vote down vote up
public ButtonToolBar() {

		setMargin(new Insets(0, 5, 5, 5));
		setFloatable(false);
		setOpaque(false);
		setBorderPainted(false);

	}
 
Example 32
Project: pcgen   File: PortraitPane.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Dimension getPreferredSize()
{
	Insets insets = getInsets();
	int width = 0;
	int height = 0;

	if (insets != null)
	{
		width += insets.left + insets.right;
		height += insets.top + insets.bottom;
	}
	if (portrait != null)
	{
		if (scale < 1)
		{
			width += (int) (scale * portrait.getWidth());
			height += (int) (scale * portrait.getHeight());
		}
		else
		{
			width += portrait.getWidth();
			height += portrait.getHeight();
		}
	}
	return new Dimension(width, height);
}
 
Example 33
Project: Spark   File: RosterMemberCallButton.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Decorates the button with the approriate UI configurations.
 */
private void decorate() {
    setBorderPainted(false);
    setOpaque(true);

    setContentAreaFilled(false);
    setMargin(new Insets(0, 0, 0, 0));
}
 
Example 34
Project: gcs   File: OutlineHeader.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * @param column The column.
 * @return The bounds of the specified header column.
 */
public Rectangle getColumnBounds(Column column) {
    Insets    insets = getInsets();
    Rectangle bounds = new Rectangle(insets.left, insets.top, getWidth() - (insets.left + insets.right), getHeight() - (insets.top + insets.bottom));
    bounds.x = mOwner.getColumnStart(column);
    bounds.width = column.getWidth();
    return bounds;
}
 
Example 35
Project: openjdk-jdk8u-backup   File: GroupLayout.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void setBounds(Insets insets, int parentWidth, boolean ltr) {
    int x = horizontalSpring.getOrigin();
    int w = horizontalSpring.getSize();
    int y = verticalSpring.getOrigin();
    int h = verticalSpring.getSize();

    if (!ltr) {
        x = parentWidth - x - w;
    }
    component.setBounds(x + insets.left, y + insets.top, w, h);
}
 
Example 36
Project: openjdk-jdk8u-backup   File: BasicGraphicsUtils.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static Dimension getPreferredButtonSize(AbstractButton b, int textIconGap)
{
    if(b.getComponentCount() > 0) {
        return null;
    }

    Icon icon = b.getIcon();
    String text = b.getText();

    Font font = b.getFont();
    FontMetrics fm = b.getFontMetrics(font);

    Rectangle iconR = new Rectangle();
    Rectangle textR = new Rectangle();
    Rectangle viewR = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);

    SwingUtilities.layoutCompoundLabel(
        b, fm, text, icon,
        b.getVerticalAlignment(), b.getHorizontalAlignment(),
        b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
        viewR, iconR, textR, (text == null ? 0 : textIconGap)
    );

    /* The preferred size of the button is the size of
     * the text and icon rectangles plus the buttons insets.
     */

    Rectangle r = iconR.union(textR);

    Insets insets = b.getInsets();
    r.width += insets.left + insets.right;
    r.height += insets.top + insets.bottom;

    return r.getSize();
}
 
Example 37
Project: TencentKona-8   File: EnableButton.java    License: GNU General Public License v2.0 5 votes vote down vote up
public EnableButton(Group group, int type) {
    super(icons[type]);
    this.group = group;
    this.type = type;
    addActionListener(this);
    setMargin(new Insets(0, 0, 0, 0));
    setBorderPainted(false);
}
 
Example 38
Project: JDKSourceCode1.8   File: SynthParser.java    License: MIT License 5 votes vote down vote up
/**
 * Convenience method to return an Insets object.
 */
private Insets parseInsets(String insets, String errorMsg) throws
                    SAXException {
    StringTokenizer tokenizer = new StringTokenizer(insets);
    return new Insets(nextInt(tokenizer, errorMsg),
                      nextInt(tokenizer, errorMsg),
                      nextInt(tokenizer, errorMsg),
                      nextInt(tokenizer, errorMsg));
}
 
Example 39
Project: netbeans   File: EditorFindSupport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Ensure that the given region will be visible in the view
 * with the appropriate find insets.
 */
private void ensureVisible(JTextComponent c, int startOffset, int endOffset, Insets extraInsets) {
    try {
        Rectangle startBounds = c.modelToView(startOffset);
        Rectangle endBounds = c.modelToView(endOffset);
        if (startBounds != null && endBounds != null) {
            startBounds.add(endBounds);
            if (extraInsets != null) {
                Rectangle visibleBounds = c.getVisibleRect();
                int extraTop = (extraInsets.top < 0)
                    ? -extraInsets.top * visibleBounds.height / 100 // percentage
                    : extraInsets.top * endBounds.height; // line count
                startBounds.y -= extraTop;
                startBounds.height += extraTop;
                startBounds.height += (extraInsets.bottom < 0)
                    ? -extraInsets.bottom * visibleBounds.height / 100 // percentage
                    : extraInsets.bottom * endBounds.height; // line count
                int extraLeft = (extraInsets.left < 0)
                    ? -extraInsets.left * visibleBounds.width / 100 // percentage
                    : extraInsets.left * endBounds.width; // char count
                startBounds.x -= extraLeft;
                startBounds.width += extraLeft;
                startBounds.width += (extraInsets.right < 0)
                    ? -extraInsets.right * visibleBounds.width / 100 // percentage
                    : extraInsets.right * endBounds.width; // char count
            }
            c.scrollRectToVisible(startBounds);
        }
    } catch (BadLocationException e) {
        // do not scroll
    }
}
 
Example 40
Project: VanetSim   File: EditSettingsControlPanel.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the panel which is shown when mix zones are enabled.
 * 
 * @return the mix zones panel
 */
private final JPanel createMixPanel(){
	JPanel panel = new JPanel();
	panel.setOpaque(false);
	panel.setLayout(new GridBagLayout());
	
	GridBagConstraints c = new GridBagConstraints();
	c.fill = GridBagConstraints.BOTH;
	c.anchor = GridBagConstraints.PAGE_START;
	c.weightx = 1;
	c.gridx = 0;
	c.gridy = 0;
	c.gridheight = 1;
	c.insets = new Insets(5,0,5,0);
	
	JLabel jLabel1 = new JLabel(Messages.getString("EditSettingsControlPanel.mixZoneSize")); //$NON-NLS-1$
	panel.add(jLabel1,c);		
	mixZoneRadius_ = new JFormattedTextField(NumberFormat.getIntegerInstance());
	mixZoneRadius_.setPreferredSize(new Dimension(60,20));
	mixZoneRadius_.setValue(100);
	mixZoneRadius_.addPropertyChangeListener("value", this); //$NON-NLS-1$
	c.gridx = 1;
	c.weightx = 0;
	panel.add(mixZoneRadius_,c);
	
	c.gridx = 0;
	c.gridwidth = 2;
	++c.gridy;
	fallbackInMixZonesCheckBox_ = new JCheckBox(Messages.getString("EditSettingsControlPanel.fallbackCommunicationInMixZones"), true); //$NON-NLS-1$
	fallbackInMixZonesCheckBox_.addItemListener(this);
	panel.add(fallbackInMixZonesCheckBox_,c);
	
	++c.gridy;
	fallbackInMixZonesPanel_ = createMixFallBackPanel();
	panel.add(fallbackInMixZonesPanel_,c);
	
	return panel;
}