javax.swing.border.Border Java Examples

The following examples show how to use javax.swing.border.Border. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FlatOptionPaneUI.java    From FlatLaf with Apache License 2.0 6 votes vote down vote up
private void updateChildPanels( Container c ) {
	for( Component child : c.getComponents() ) {
		if( child instanceof JPanel ) {
			JPanel panel = (JPanel)child;

			// make sub-panel non-opaque for OptionPane.background
			panel.setOpaque( false );

			// use non-UIResource borders to avoid that they are replaced when switching LaF
			Border border = panel.getBorder();
			if( border instanceof UIResource )
				panel.setBorder( new NonUIResourceBorder( border ) );
		}

		if( child instanceof Container ) {
			updateChildPanels( (Container) child );
		}
	}
}
 
Example #2
Source File: BasicOptionPaneUI.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates and returns a Container containing the buttons. The buttons
 * are created by calling <code>getButtons</code>.
 */
protected Container createButtonArea() {
    JPanel bottom = new JPanel();
    Border border = (Border)DefaultLookup.get(optionPane, this,
                                      "OptionPane.buttonAreaBorder");
    bottom.setName("OptionPane.buttonArea");
    if (border != null) {
        bottom.setBorder(border);
    }
    bottom.setLayout(new ButtonAreaLayout(
       DefaultLookup.getBoolean(optionPane, this,
                                "OptionPane.sameSizeButtons", true),
       DefaultLookup.getInt(optionPane, this, "OptionPane.buttonPadding",
                            6),
       DefaultLookup.getInt(optionPane, this,
                    "OptionPane.buttonOrientation", SwingConstants.CENTER),
       DefaultLookup.getBoolean(optionPane, this, "OptionPane.isYesLast",
                                false)));
    addButtonComponents(bottom, getButtons(), getInitialValueIndex());
    return bottom;
}
 
Example #3
Source File: JTextField.java    From i18n-editor with MIT License 6 votes vote down vote up
/**
 * Constructs a {@link JTextField} with an initial text.
 */
public JTextField(String text) {
	super(text, 25);
	
	Border border = BorderFactory.createLineBorder(Colors.scale(UIManager.getColor("Panel.background"), .8f));
	setBorder(BorderFactory.createCompoundBorder(border, BorderFactory.createEmptyBorder(5,8,5,8)));
	getDocument().addUndoableEditListener(e -> undoManager.addEdit(e.getEdit()));
	
	// Add undo support
	getActionMap().put("undo", new UndoAction(undoManager));
	getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "undo");
	
	// Add redo support
	getActionMap().put("redo", new RedoAction(undoManager));
	getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_Y, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "redo");
	
	// Add popup menu support
	addMouseListener(new JTextComponentMenuListener(this, undoManager));
}
 
Example #4
Source File: EditorView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Handles special border policy - scroll pane like border only 
 * if editor area is null.
 */
private void manageBorder (JPanel panel) {
    if (editorArea != null) {
        panel.setBorder(null);
    } else {
        if (Utilities.isMac()) {
           //#64701 on macosx the nb.scrollpane.border draws ugly line on top
            panel.setBorder(BorderFactory.createEmptyBorder());
        } else {
            Border border = UIManager.getBorder( "Nb.EmptyEditorArea.border"); //NOI18N
            if( null == border ) {
                // special border installed into UI manager by netbeans
                border = UIManager.getBorder("Nb.ScrollPane.border"); //NOI18N
            }
            panel.setBorder(border);
 }
    }
}
 
Example #5
Source File: BERootPaneUI.java    From beautyeye with Apache License 2.0 6 votes vote down vote up
/**
 * Installs the appropriate <code>Border</code> onto the
 * <code>JRootPane</code>.
 *
 * @param root the root
 */
void installBorder(JRootPane root) 
{
	int style = root.getWindowDecorationStyle();

	if (style == JRootPane.NONE) 
	{
		LookAndFeel.uninstallBorder(root);
	}
	else 
	{
		Border b = root.getBorder();
		if (b == null || b instanceof UIResource) 
		{
			root.setBorder(null);
			root.setBorder(UIManager.getBorder(borderKeys[style]));
		}
	}
}
 
Example #6
Source File: BasicOptionPaneUI.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a {@code Container} containing the buttons.
 * The buttons are created by calling {@code getButtons}.
 *
 * @return a {@code Container} containing the buttons
 */
protected Container createButtonArea() {
    JPanel bottom = new JPanel();
    Border border = (Border)DefaultLookup.get(optionPane, this,
                                      "OptionPane.buttonAreaBorder");
    bottom.setName("OptionPane.buttonArea");
    if (border != null) {
        bottom.setBorder(border);
    }
    bottom.setLayout(new ButtonAreaLayout(
       DefaultLookup.getBoolean(optionPane, this,
                                "OptionPane.sameSizeButtons", true),
       DefaultLookup.getInt(optionPane, this, "OptionPane.buttonPadding",
                            6),
       DefaultLookup.getInt(optionPane, this,
                    "OptionPane.buttonOrientation", SwingConstants.CENTER),
       DefaultLookup.getBoolean(optionPane, this, "OptionPane.isYesLast",
                                false)));
    addButtonComponents(bottom, getButtons(), getInitialValueIndex());
    return bottom;
}
 
Example #7
Source File: AnalyzerPanel.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private Component buildPhasePanel() {
	phasePanel = new JPanel(new MiddleLayout());
	Border empty = BorderFactory.createEmptyBorder(0, 20, 0, 20);
	Border etched = BorderFactory.createEtchedBorder();
	phasePanel.setBorder(BorderFactory.createCompoundBorder(etched, empty));
	phasePanel.setOpaque(false);
	phasePanel.setPreferredSize(new Dimension(60, 0));
	phaseLabel = new GDLabel("");

	//@formatter:off
	String text = analyzer.getAnalysisType() == AnalyzerType.ONE_SHOT_ANALYZER ? 
		  "Phase when this analyzer runs. (Select and press number to change)"
		: "Phase when this analyzer first becomes active. (Select and press number to change)";
	//@formatter:on

	phaseLabel.setToolTipText(text);
	phasePanel.setToolTipText(text);
	updatePhaseLabel();
	phasePanel.add(phaseLabel);
	return phasePanel;
}
 
Example #8
Source File: SynthStyle.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Uninstalls any state that this style installed on
 * the <code>JComponent</code> from <code>context</code>.
 * <p>
 * Styles should NOT depend upon this being called, in certain cases
 * it may never be called.
 *
 * @param context SynthContext identifying component to install properties
 *        to.
 */
public void uninstallDefaults(SynthContext context) {
    if (!context.isSubregion()) {
        // NOTE: because getForeground, getBackground and getFont will look
        // at the parent Container, if we set them to null it may
        // mean we they return a non-null and non-UIResource value
        // preventing install from correctly settings its colors/font. For
        // this reason we do not uninstall the fg/bg/font.

        JComponent c = context.getComponent();
        Border border = c.getBorder();

        if (border instanceof UIResource) {
            c.setBorder(null);
        }
    }
}
 
Example #9
Source File: DefaultsDisplay.java    From beautyeye with Apache License 2.0 6 votes vote down vote up
protected void setBorder(JComponent renderer, boolean hasFocus, boolean isSelected) {

    if (hasFocus) {
        Border border = null;
        if (isSelected) {
            border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
        }
        if (border == null) {
            border = UIManager.getBorder("Table.focusCellHighlightBorder");
        }
        renderer.setBorder(border);
                        
    } else {
        renderer.setBorder(noFocusBorder);
    }
}
 
Example #10
Source File: NewItemWithTemplatesPopupPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private JBList<T> createTemplatesList(@Nonnull ListModel<T> model, ListCellRenderer<T> renderer) {
  JBList<T> list = new JBList<>(model);
  MouseAdapter mouseListener = new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
      if (myApplyAction != null && e.getClickCount() > 1) myApplyAction.consume(e);
    }
  };

  list.addMouseListener(mouseListener);
  list.setCellRenderer(renderer);
  list.setFocusable(false);
  list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

  Border border = JBUI.Borders.merge(JBUI.Borders.emptyLeft(JBUIScale.scale(5)), JBUI.Borders.customLine(JBUI.CurrentTheme.NewClassDialog.bordersColor(), 1, 0, 0, 0), true);
  list.setBorder(border);
  return list;
}
 
Example #11
Source File: SeaGlassBrowser.java    From seaglass with Apache License 2.0 6 votes vote down vote up
static void printBorder(PrintWriter html, Border border) {
    Insets insets = border.getBorderInsets(new JToolBar());
    html.println("<td>Border Insets(" + insets.top + "," + insets.left + "," + insets.bottom + "," + insets.right
            + ")</pre></td>");
    int w = 50 + insets.left + insets.right;
    int h = 20 + insets.top + insets.bottom;
    try {
        BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = img.createGraphics();
        Composite old = g2.getComposite();
        g2.setComposite(AlphaComposite.Clear);
        g2.fillRect(0, 0, w, h);
        g2.setComposite(old);
        g2.setColor(Color.RED);
        g2.fillRect(insets.left, insets.top, 49, 19);
        border.paintBorder(null, g2, 0, 0, w, h);
        g2.dispose();
        html.println("<td>" + saveImage(img) + "</td>");
    } catch (Exception e) {
        // e.printStackTrace();
        html.println("<td>NPE&nbsp;</td>");
    }
}
 
Example #12
Source File: AquaButtonUI.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void installDefaults(final AbstractButton b) {
    // load shared instance defaults
    final String pp = getPropertyPrefix();

    if (!defaults_initialized) {
        defaultDisabledTextColor = UIManager.getColor(pp + "disabledText");
        defaults_initialized = true;
    }

    setButtonMarginIfNeeded(b, UIManager.getInsets(pp + "margin"));

    LookAndFeel.installColorsAndFont(b, pp + "background", pp + "foreground", pp + "font");
    LookAndFeel.installProperty(b, "opaque", UIManager.getBoolean(pp + "opaque"));

    final Object borderProp = b.getClientProperty(BUTTON_TYPE);
    boolean hasBorder = false;

    if (borderProp != null) {
        hasBorder = setButtonType(b, borderProp);
    }
    if (!hasBorder) setThemeBorder(b);

    final Object segmentProp = b.getClientProperty(SEGMENTED_BUTTON_POSITION);
    if (segmentProp != null) {
        final Border border = b.getBorder();
        if (!(border instanceof AquaBorder)) return;

        b.setBorder(AquaButtonExtendedTypes.getBorderForPosition(b, b.getClientProperty(BUTTON_TYPE), segmentProp));
    }
}
 
Example #13
Source File: AquaButtonUI.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public Dimension getPreferredSize(final JComponent c) {
    final AbstractButton b = (AbstractButton)c;

    // fix for Radar #3134273
    final Dimension d = BasicGraphicsUtils.getPreferredButtonSize(b, b.getIconTextGap());
    if (d == null) return null;

    final Border border = b.getBorder();
    if (border instanceof AquaButtonBorder) {
        ((AquaButtonBorder)border).alterPreferredSize(d);
    }

    return d;
}
 
Example #14
Source File: ModernButtonUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void paint(Graphics g, JComponent c) {
  final Border border = c.getBorder();
  if (border != null) {
    final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
    final boolean square = isSquare(c);

    final Insets ins = border.getBorderInsets(c);
    final int yOff = (ins.top + ins.bottom) / 4;

    if (c.isEnabled()) {
      if (!square) {
        if (myMouseEnterHandler.isMousePressed()) {
          g.setColor(ColorUtil.toAlpha(ModernUIUtil.getSelectionBackground(), 100));
        }
        else {
          if (ModernButtonBorderPainter.isDefaultButton(c)) {
            g.setColor(myMouseEnterHandler.isMouseEntered() ? ModernUIUtil.getSelectionBackground().brighter() : ModernUIUtil.getSelectionBackground());
          }
          else {
            g.setColor(getButtonColor1());
          }
        }
      }
    }
    else {
      if (ModernButtonBorderPainter.isDefaultButton(c)) {
        g.setColor(ModernUIUtil.getActiveBorderColor());
      }
    }

    g.fillRect(JBUI.scale(square ? 2 : 4), yOff, c.getWidth() - JBUI.scale(2 * 4), c.getHeight() - 2 * yOff);
    config.restore();
  }
  super.paint(g, c);
}
 
Example #15
Source File: BasicSplitPaneDivider.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #16
Source File: SynthStyle.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
void installDefaults(SynthContext context, SynthUI ui) {
    // Special case the Border as this will likely change when the LAF
    // can have more control over this.
    if (!context.isSubregion()) {
        JComponent c = context.getComponent();
        Border border = c.getBorder();

        if (border == null || border instanceof UIResource) {
            c.setBorder(new SynthBorder(ui, getInsets(context, null)));
        }
    }
    installDefaults(context);
}
 
Example #17
Source File: Test4856008.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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());
    }
}
 
Example #18
Source File: AJTextArea.java    From egdownloader with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 可以设置坐标及大小,有边框,可编辑<br>
 * @param x
 * @param y
 * @param width
 * @param height
 */
public AJTextArea(int x, int y, int width, int height, String borderTitle) {
	this.setAutoscrolls(true);
	Border border1 = BorderFactory.createLineBorder(new Color(219,219,219));
	Border border = BorderFactory.createTitledBorder(border1, borderTitle);
	this.setBorder(border);
	this.setBounds(x, y, width, height);
	// 下面这行代码是自动滚动的关键代码
	this.setLineWrap(true);
	popup(this);
}
 
Example #19
Source File: WindowsToolBarUI.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected Border createRolloverBorder() {
    if (XPStyle.getXP() != null) {
        return new EmptyBorder(3, 3, 3, 3);
    } else {
        return super.createRolloverBorder();
    }
}
 
Example #20
Source File: EnhancedTableCellRenderer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setBorder(Border border) {
    super.setBorder(border);
    originalBorder = border;

    if (originalBorder != null) {
        originalBorderInsets = originalBorder.getBorderInsets(this);
    }
}
 
Example #21
Source File: Test6657026.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static Border create(String name) {
    try {
        name = "javax.swing.plaf.metal.MetalBorders$" + name;
        return (Border) Class.forName(name).newInstance();
    }
    catch (Exception exception) {
        throw new Error("unexpected exception", exception);
    }
}
 
Example #22
Source File: FormUtils.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Create Titled Border
 * @param name the title
 * @return Border
 */
public static Border createTitledBorder(String name) {
	Border margin = BorderFactory.createEmptyBorder(10, 10, 10, 10);
	Border title = BorderFactory.createTitledBorder(name);
	
	return BorderFactory.createCompoundBorder(title, margin);
}
 
Example #23
Source File: AquaButtonUI.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public Dimension getPreferredSize(final JComponent c) {
    final AbstractButton b = (AbstractButton)c;

    // fix for Radar #3134273
    final Dimension d = BasicGraphicsUtils.getPreferredButtonSize(b, b.getIconTextGap());
    if (d == null) return null;

    final Border border = b.getBorder();
    if (border instanceof AquaButtonBorder) {
        ((AquaButtonBorder)border).alterPreferredSize(d);
    }

    return d;
}
 
Example #24
Source File: BasicSplitPaneUI.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Uninstalls the UI defaults.
 */
protected void uninstallDefaults() {
    if(splitPane.getLayout() == layoutManager) {
        splitPane.setLayout(null);
    }

    if(nonContinuousLayoutDivider != null) {
        splitPane.remove(nonContinuousLayoutDivider);
    }

    LookAndFeel.uninstallBorder(splitPane);

    Border    b = divider.getBorder();

    if (b instanceof UIResource) {
        divider.setBorder(null);
    }

    splitPane.remove(divider);
    divider.setBasicSplitPaneUI(null);
    layoutManager = null;
    divider = null;
    nonContinuousLayoutDivider = null;

    setNonContinuousLayoutDivider(null);

    // sets the focus forward and backward traversal keys to null
    // to restore the defaults
    splitPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
    splitPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
}
 
Example #25
Source File: SynthStyle.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void installDefaults(SynthContext context, SynthUI ui) {
    // Special case the Border as this will likely change when the LAF
    // can have more control over this.
    if (!context.isSubregion()) {
        JComponent c = context.getComponent();
        Border border = c.getBorder();

        if (border == null || border instanceof UIResource) {
            c.setBorder(new SynthBorder(ui, getInsets(context, null)));
        }
    }
    installDefaults(context);
}
 
Example #26
Source File: WindowsToolBarUI.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected Border createRolloverBorder() {
    if (XPStyle.getXP() != null) {
        return new EmptyBorder(3, 3, 3, 3);
    } else {
        return super.createRolloverBorder();
    }
}
 
Example #27
Source File: MultipleActionDockingToolbarButton.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private Shape createPopupContext() {
	if (entireButtonShowsPopupMenu) {
		return new Rectangle(0, 0, getWidth(), getHeight());
	}

	Border buttonBorder = getBorder();
	Insets borderInsets =
		buttonBorder == null ? new Insets(0, 0, 0, 0) : buttonBorder.getBorderInsets(this);
	int leftIconWidth = primaryIcon.getIconWidth() + (borderInsets.left + borderInsets.right);
	int rightButtonWidth =
		ARROW_WIDTH + ARROW_PADDING + (borderInsets.left + borderInsets.right);
	int height = getIcon().getIconHeight() + borderInsets.top + borderInsets.bottom;
	return new Rectangle(leftIconWidth, 0, rightButtonWidth, height);
}
 
Example #28
Source File: MorphBorder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private Border getBorder() {
  long modificationCount = ourTracker.getModificationCount();
  if (myLastModificationCount == modificationCount) {
    return myLastComputedBorder;
  }

  myLastModificationCount = modificationCount;
  return myLastComputedBorder = myBorderProducer.produce();
}
 
Example #29
Source File: WindowsToolBarUI.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * @since 1.6
 */
protected Border getRolloverBorder(AbstractButton b) {
    XPStyle xp = XPStyle.getXP();
    if (xp != null) {
        return xp.getBorder(b, WindowsButtonUI.getXPButtonType(b));
    } else {
        return super.getRolloverBorder(b);
    }
}
 
Example #30
Source File: BasicOptionPaneUI.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Messaged from installComponents to create a Container containing the
 * body of the message. The icon is the created by calling
 * <code>addIcon</code>.
 */
protected Container createMessageArea() {
    JPanel top = new JPanel();
    Border topBorder = (Border)DefaultLookup.get(optionPane, this,
                                         "OptionPane.messageAreaBorder");
    if (topBorder != null) {
        top.setBorder(topBorder);
    }
    top.setLayout(new BorderLayout());

    /* Fill the body. */
    Container          body = new JPanel(new GridBagLayout());
    Container          realBody = new JPanel(new BorderLayout());

    body.setName("OptionPane.body");
    realBody.setName("OptionPane.realBody");

    if (getIcon() != null) {
        JPanel sep = new JPanel();
        sep.setName("OptionPane.separator");
        sep.setPreferredSize(new Dimension(15, 1));
        realBody.add(sep, BorderLayout.BEFORE_LINE_BEGINS);
    }
    realBody.add(body, BorderLayout.CENTER);

    GridBagConstraints cons = new GridBagConstraints();
    cons.gridx = cons.gridy = 0;
    cons.gridwidth = GridBagConstraints.REMAINDER;
    cons.gridheight = 1;
    cons.anchor = DefaultLookup.getInt(optionPane, this,
                  "OptionPane.messageAnchor", GridBagConstraints.CENTER);
    cons.insets = new Insets(0,0,3,0);

    addMessageComponents(body, cons, getMessage(),
                      getMaxCharactersPerLineCount(), false);
    top.add(realBody, BorderLayout.CENTER);

    addIcon(top);
    return top;
}