Java Code Examples for javax.swing.border.Border

The following examples show how to use javax.swing.border.Border. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: consulo   Source File: NewItemWithTemplatesPopupPanel.java    License: 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 2
Source Project: netbeans   Source File: EditorView.java    License: 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 3
/**
 * 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 4
Source Project: Bytecoder   Source File: BasicOptionPaneUI.java    License: 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 5
Source Project: FlatLaf   Source File: FlatOptionPaneUI.java    License: 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 6
Source Project: openjdk-8   Source File: SynthStyle.java    License: 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 7
Source Project: beautyeye   Source File: DefaultsDisplay.java    License: 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 8
Source Project: seaglass   Source File: SeaGlassBrowser.java    License: 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 9
Source Project: i18n-editor   Source File: JTextField.java    License: 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 10
Source Project: ghidra   Source File: AnalyzerPanel.java    License: 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 11
Source Project: beautyeye   Source File: BERootPaneUI.java    License: 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 12
protected Border createRolloverBorder() {
    if (XPStyle.getXP() != null) {
        return new EmptyBorder(3, 3, 3, 3);
    } else {
        return super.createRolloverBorder();
    }
}
 
Example 13
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 5 votes vote down vote up
protected FileNameRenderer(JTable table) {
  Border b = UIManager.getBorder("Table.noFocusBorder");
  if (Objects.isNull(b)) { // Nimbus???
    Insets i = focusBorder.getBorderInsets(textLabel);
    b = BorderFactory.createEmptyBorder(i.top, i.left, i.bottom, i.right);
  }
  noFocusBorder = b;

  JPanel p = new JPanel(new BorderLayout()) {
    @Override public Dimension getPreferredSize() {
      return dim;
    }
  };
  p.setOpaque(false);
  renderer.setOpaque(false);

  // [XP Style Icons - Download](https://xp-style-icons.en.softonic.com/)
  icon = new ImageIcon(getClass().getResource("wi0063-16.png"));

  ImageProducer ip = new FilteredImageSource(icon.getImage().getSource(), new SelectedImageFilter());
  selectedIcon = new ImageIcon(p.createImage(ip));

  iconLabel = new JLabel(icon);
  iconLabel.setBorder(BorderFactory.createEmptyBorder());

  p.add(iconLabel, BorderLayout.WEST);
  p.add(textLabel);
  renderer.add(p, BorderLayout.WEST);

  Dimension d = iconLabel.getPreferredSize();
  dim.setSize(d);
  table.setRowHeight(d.height);
}
 
Example 14
Source Project: jdk8u-dev-jdk   Source File: AquaComboBoxUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void applySizeFor(final JComponent c, final Size size) {
    if (arrowButton == null) return;
    final Border border = arrowButton.getBorder();
    if (!(border instanceof AquaButtonBorder)) return;
    final AquaButtonBorder aquaBorder = (AquaButtonBorder)border;
    arrowButton.setBorder(aquaBorder.deriveBorderForSize(size));
}
 
Example 15
Source Project: MercuryTrade   Source File: AbstractMovableComponentFrame.java    License: MIT License 5 votes vote down vote up
MovableFrameConstraints(boolean processSEResize,
                        boolean processEResize,
                        boolean visible,
                        Color bgColor,
                        Border border,
                        Point location) {
    this.processSEResize = processSEResize;
    this.processEResize = processEResize;
    this.visible = visible;
    this.bgColor = bgColor;
    this.border = border;
    this.location = location;
}
 
Example 16
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 17
/**
 * 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 18
Source Project: jdk8u_jdk   Source File: AquaButtonUI.java    License: 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 19
/**
 * If <code>c</code> is a check box or radio button, and the border is
 * not painted this returns the inset along the specified axis.
 */
public int getButtonGap(JComponent c, int position) {
    String classID = c.getUIClassID();
    if ((classID == "CheckBoxUI" || classID == "RadioButtonUI") &&
            !((AbstractButton)c).isBorderPainted()) {
        Border border = c.getBorder();
        if (border instanceof UIResource) {
            return getInset(c, position);
        }
    }
    return 0;
}
 
Example 20
private FilterTopComponent() {
    filterSettingsChangedEvent = new ChangedEvent<FilterTopComponent>(this);
    initComponents();
    setName(NbBundle.getMessage(FilterTopComponent.class, "CTL_FilterTopComponent"));
    setToolTipText(NbBundle.getMessage(FilterTopComponent.class, "HINT_FilterTopComponent"));
    //        setIcon(Utilities.loadImage(ICON_PATH, true));

    sequence = new FilterChain();
    filterChain = new FilterChain();
    initFilters();
    manager = new ExplorerManager();
    manager.setRootContext(new AbstractNode(new FilterChildren()));
    associateLookup(ExplorerUtils.createLookup(manager, getActionMap()));
    view = new CheckListView();

    ToolbarPool.getDefault().setPreferredIconSize(16);
    Toolbar toolBar = new Toolbar();
    Border b = (Border) UIManager.get("Nb.Editor.Toolbar.border"); //NOI18N
    toolBar.setBorder(b);
    comboBox = new JComboBox();
    toolBar.add(comboBox);
    this.add(toolBar, BorderLayout.NORTH);
    toolBar.add(SaveFilterSettingsAction.get(SaveFilterSettingsAction.class));
    toolBar.add(RemoveFilterSettingsAction.get(RemoveFilterSettingsAction.class));
    toolBar.addSeparator();
    toolBar.add(MoveFilterUpAction.get(MoveFilterUpAction.class).createContextAwareInstance(this.getLookup()));
    toolBar.add(MoveFilterDownAction.get(MoveFilterDownAction.class).createContextAwareInstance(this.getLookup()));
    toolBar.add(RemoveFilterAction.get(RemoveFilterAction.class).createContextAwareInstance(this.getLookup()));
    toolBar.add(NewFilterAction.get(NewFilterAction.class));
    this.add(view, BorderLayout.CENTER);

    filterSettings = new ArrayList<FilterSetting>();
    updateComboBox();

    comboBox.addActionListener(comboBoxActionListener);
    setChain(filterChain);
}
 
Example 21
Source Project: jdk8u-jdk   Source File: Test6963870.java    License: GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 22
Source Project: openjdk-jdk9   Source File: Test4856008.java    License: 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 23
Source Project: netbeans   Source File: EnhancedTableCellRenderer.java    License: 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 24
Source Project: openjdk-8-source   Source File: Test6657026.java    License: 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 25
Source Project: jdal   Source File: FormUtils.java    License: 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 26
Source Project: ghidra   Source File: MultipleActionDockingToolbarButton.java    License: 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 27
Source Project: consulo   Source File: MorphBorder.java    License: 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 28
/**
 * 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;
}
 
Example 29
/**
 * {@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 Project: jdk8u60   Source File: SynthStyle.java    License: 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);
}