Java Code Examples for javax.swing.JButton#setBorder()

The following examples show how to use javax.swing.JButton#setBorder() . 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: MainMenuFrame.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public MainMenuFrame(String title) {
	super(title);
	contentPanel.setBorder(new EmptyBorder(25, 25, 25, 25));
	contentPanel.setLayout(new GridLayout(3, 0, 0, 25));

	btnAdd = new JButton("Add");
	btnAdd.setFont(BUTTON_FONT);
	btnAdd.setBackground(BUTTON_BACKGROUND);
	btnAdd.setBorder(BorderFactory.createRaisedBevelBorder());
	contentPanel.add(btnAdd);

	btnList = new JButton("List");
	btnList.setFont(BUTTON_FONT);
	btnList.setBackground(BUTTON_BACKGROUND);
	btnList.setBorder(BorderFactory.createRaisedBevelBorder());
	contentPanel.add(btnList);

	btnSaveAndExit = new JButton("Save and Exit");
	btnSaveAndExit.setFont(BUTTON_FONT);
	btnSaveAndExit.setBackground(BUTTON_BACKGROUND);
	btnSaveAndExit.setBorder(BorderFactory.createRaisedBevelBorder());
	contentPanel.add(btnSaveAndExit);
}
 
Example 2
Source File: hover_press_utilclass.java    From java-QQ- with Apache License 2.0 5 votes vote down vote up
public static JButton getbtnClose()
{
	JButton btnclose=new JButton();
	btnclose.setIcon(new ImageIcon("image/close.png"));
	btnclose.setRolloverIcon(new ImageIcon("image/close_hover.png"));
	btnclose.setPressedIcon(new ImageIcon("image/close_press.png"));
	btnclose.setBorder(null);
	return btnclose;
}
 
Example 3
Source File: FatalErrorDialog.java    From launcher with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public FatalErrorDialog addButton(String message, Runnable action)
{
	JButton button = new JButton(message);
	button.addActionListener(e -> action.run());
	button.setFont(font);
	button.setBackground(DARK_GRAY_COLOR);
	button.setForeground(Color.LIGHT_GRAY);
	button.setBorder(BorderFactory.createCompoundBorder(
		BorderFactory.createMatteBorder(1, 0, 0, 0, DARK_GRAY_COLOR.brighter()),
		new EmptyBorder(4, 4, 4, 4)
	));
	button.setAlignmentX(Component.CENTER_ALIGNMENT);
	button.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
	button.setFocusPainted(false);
	button.addChangeListener(ev ->
	{
		if (button.getModel().isPressed())
		{
			button.setBackground(DARKER_GRAY_COLOR);
		}
		else if (button.getModel().isRollover())
		{
			button.setBackground(DARK_GRAY_HOVER_COLOR);
		}
		else
		{
			button.setBackground(DARK_GRAY_COLOR);
		}
	});

	rightColumn.add(button);
	rightColumn.revalidate();

	return this;
}
 
Example 4
Source File: EntityAction.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates an action, and registers the action in the provided menu as
 * well as in the toolbar (if so desired)
 *
 * @param entityActions collection of actions that depend on existence of a
 *                      current entity, or null
 * @param menu          the menu where the related item is to be inserted
 * @param toolBar       the toolBar for icon insertion (if so desired), or
 *                      null
 * @param label         label for the menu item
 * @param tip           tooltip text
 * @param key           accelerator key, or null
 * @param icon          icon for menu and toolbar, or null
 */
protected EntityAction (Collection<Action> entityActions,
                        JMenu menu,
                        JToolBar toolBar,
                        String label,
                        String tip,
                        String key,
                        Icon icon)
{
    super(label, icon);

    // Entity-dependent action ?
    if (entityActions != null) {
        entityActions.add(this);
    }

    // Always add the related Menu item
    JMenuItem item = menu.add(this);

    // Tooltip
    putValue(SHORT_DESCRIPTION, tip);

    // Accelerator key?
    if (key != null) {
        item.setAccelerator(
                KeyStroke.getKeyStroke(
                (int) key.charAt(0),
                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    }

    // Add an icon in the Tool bar?
    if ((toolBar != null) && (icon != null)) {
        final JButton button = toolBar.add(this);
        button.setBorder(UIUtil.getToolBorder());
    }
}
 
Example 5
Source File: CloseButtonFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a small 'close' JButton with close icon, rollover icon and pressed icon according to Look and Feel
 *
 * @return JButton with close icons.
 */
public static JButton createCloseButton() {
    JButton closeButton = new JButton();
    int size = 16;
    closeButton.setPreferredSize(new Dimension(size, size));
    closeButton.setContentAreaFilled(false);
    closeButton.setFocusable(false);
    closeButton.setBorder(BorderFactory.createEmptyBorder());
    closeButton.setBorderPainted(false);
    closeButton.setRolloverEnabled(true);
    closeButton.setIcon(getCloseTabImage());
    closeButton.setRolloverIcon(getCloseTabRolloverImage());
    closeButton.setPressedIcon(getCloseTabPressedImage());
    return closeButton;
}
 
Example 6
Source File: SlownessReporter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JButton createDetails(String text) {
    JButton btn = new HtmlButton(text);
    btn.setFocusable(false);
    btn.setBorder(BorderFactory.createEmptyBorder());
    btn.setBorderPainted(false);
    btn.setFocusPainted(false);
    btn.setOpaque(false);
    btn.setContentAreaFilled(false);
    btn.addActionListener(this);
    btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    return btn;
}
 
Example 7
Source File: TerminalSettingsAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static JButton createButton(String iconPath, String tooltip) {
    Icon icon = ImageUtilities.loadImageIcon(iconPath, false);
    final JButton button = new JButton(icon);
    // ensure small size, just for the icon
    Dimension size = new Dimension(icon.getIconWidth() + 8, icon.getIconHeight() + 8);
    button.setPreferredSize(size);
    button.setMargin(new Insets(1, 1, 1, 1));
    button.setBorder(new EmptyBorder(button.getBorder().getBorderInsets(button)));
    button.setToolTipText(tooltip);
    button.setFocusable(false);
    return button;
}
 
Example 8
Source File: FatalErrorDialog.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public FatalErrorDialog addButton(String message, Runnable action)
{
	JButton button = new JButton(message);
	button.addActionListener(e -> action.run());
	button.setFont(font);
	button.setBackground(ColorScheme.DARK_GRAY_COLOR);
	button.setForeground(Color.LIGHT_GRAY);
	button.setBorder(BorderFactory.createCompoundBorder(
		BorderFactory.createMatteBorder(1, 0, 0, 0, ColorScheme.DARK_GRAY_COLOR.brighter()),
		new EmptyBorder(4, 4, 4, 4)
	));
	button.setAlignmentX(Component.CENTER_ALIGNMENT);
	button.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
	button.setFocusPainted(false);
	button.addChangeListener(ev ->
	{
		if (button.getModel().isPressed())
		{
			button.setBackground(ColorScheme.DARKER_GRAY_COLOR);
		}
		else if (button.getModel().isRollover())
		{
			button.setBackground(ColorScheme.DARK_GRAY_HOVER_COLOR);
		}
		else
		{
			button.setBackground(ColorScheme.DARK_GRAY_COLOR);
		}
	});

	rightColumn.add(button);
	rightColumn.revalidate();

	return this;
}
 
Example 9
Source File: Test4247606.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void init() {
    JButton button = new JButton("Button"); // NON-NLS: the button text
    button.setBorder(BorderFactory.createLineBorder(Color.red, 1));

    TitledBorder border = new TitledBorder("Bordered Pane"); // NON-NLS: the panel title
    border.setTitlePosition(TitledBorder.BELOW_BOTTOM);

    JPanel panel = create(button, border);
    panel.setBackground(Color.green);

    getContentPane().add(create(panel, BorderFactory.createEmptyBorder(10, 10, 10, 10)));
}
 
Example 10
Source File: Test4247606.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void init() {
    JButton button = new JButton("Button"); // NON-NLS: the button text
    button.setBorder(BorderFactory.createLineBorder(Color.red, 1));

    TitledBorder border = new TitledBorder("Bordered Pane"); // NON-NLS: the panel title
    border.setTitlePosition(TitledBorder.BELOW_BOTTOM);

    JPanel panel = create(button, border);
    panel.setBackground(Color.green);

    getContentPane().add(create(panel, BorderFactory.createEmptyBorder(10, 10, 10, 10)));
}
 
Example 11
Source File: CompactLabourReport.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
private JButton createButton(String name, ActionListener listener) {
    JButton button = new JButton(name);
    button.setMargin(new Insets(0, 0, 0, 0));
    button.setOpaque(false);
    button.setHorizontalAlignment(SwingConstants.LEADING);
    button.setForeground(Utility.LINK_COLOR);
    button.setBorder(Utility.LEFTCELLBORDER);
    button.addActionListener(listener);
    return button;
}
 
Example 12
Source File: LauncherFrame.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public void initButton( JButton button ) {
    button.setPreferredSize( new Dimension( 64, 64 ) );
    button.setMargin( new Insets( 8, 8, 8, 8 ) );
    button.setOpaque( false );
    button.setFocusPainted( false );
    button.setBorderPainted( false );
    button.setContentAreaFilled( false );
    button.setBorder( BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
}
 
Example 13
Source File: Test4247606.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void init() {
    JButton button = new JButton("Button"); // NON-NLS: the button text
    button.setBorder(BorderFactory.createLineBorder(Color.red, 1));

    TitledBorder border = new TitledBorder("Bordered Pane"); // NON-NLS: the panel title
    border.setTitlePosition(TitledBorder.BELOW_BOTTOM);

    JPanel panel = create(button, border);
    panel.setBackground(Color.green);

    getContentPane().add(create(panel, BorderFactory.createEmptyBorder(10, 10, 10, 10)));
}
 
Example 14
Source File: WidgetHelper.java    From magarena with GNU General Public License v3.0 4 votes vote down vote up
public static void setTransparent(JButton btn) {
    btn.setOpaque(false);
    btn.setContentAreaFilled(false);
    btn.setBorderPainted(false);
    btn.setBorder(null);
}
 
Example 15
Source File: Test6910490.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private JScrollPane create(String name, Dimension size, MatteBorder border) {
    JButton button = new JButton(name);
    button.setPreferredSize(size);
    button.setBorder(border);
    return new JScrollPane(button);
}
 
Example 16
Source File: Test6910490.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private JScrollPane create(String name, Dimension size, MatteBorder border) {
    JButton button = new JButton(name);
    button.setPreferredSize(size);
    button.setBorder(border);
    return new JScrollPane(button);
}
 
Example 17
Source File: Test6910490.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private JScrollPane create(String name, Dimension size, MatteBorder border) {
    JButton button = new JButton(name);
    button.setPreferredSize(size);
    button.setBorder(border);
    return new JScrollPane(button);
}
 
Example 18
Source File: PmdDataSourceEditor.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void init( final DesignTimeContext context ) {
  if ( context == null ) {
    throw new NullPointerException();
  }

  this.context = context;
  setModal( true );
  setTitle( Messages.getString( "PmdDataSourceEditor.Title" ) );

  maxPreviewRowsSpinner = new JSpinner( new SpinnerNumberModel( 10000, 1, Integer.MAX_VALUE, 1 ) );
  previewAction = new PreviewAction();
  globalTemplateAction = new GlobalTemplateAction();
  queryTemplateAction = new QueryTemplateAction();

  filenameField = new JTextField( null, 0 );
  filenameField.setColumns( 30 );
  filenameField.getDocument().addDocumentListener( new FilenameDocumentListener() );

  queryNameList = new JList();
  queryNameList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
  queryNameList.setVisibleRowCount( 5 );
  queryNameList.addListSelectionListener( new QueryNameListSelectionListener() );
  queryNameList.setCellRenderer( new QueryNameListCellRenderer() );

  queryAddButton = new BorderlessButton( new AddQueryAction() );
  queryRemoveButton = new BorderlessButton( new RemoveQueryAction() );

  queryNameTextField = new JTextField( null, 0 );
  queryNameTextField.setColumns( 35 );
  queryNameTextField.getDocument().addDocumentListener( new QueryNameTextFieldDocumentListener() );

  domainIdTextField = new JTextField( null, 0 );
  domainIdTextField.setColumns( 35 );
  domainIdTextField.getDocument().addDocumentListener( new DomainTextFieldDocumentListener() );

  queryTextArea = new RSyntaxTextArea();
  queryTextArea.setSyntaxEditingStyle( SyntaxConstants.SYNTAX_STYLE_XML );
  queryTextArea.setWrapStyleWord( true );
  queryTextArea.setLineWrap( true );
  queryTextArea.setRows( 5 );
  queryTextArea.getDocument().addDocumentListener( new QueryDocumentListener() );

  queryDesignerButton = new JButton( new QueryDesignerAction() );
  queryDesignerButton.setEnabled( false );
  queryDesignerButton.setBorder( new EmptyBorder( 0, 0, 0, 0 ) );

  globalScriptTextArea = new RSyntaxTextArea();
  globalScriptTextArea.setSyntaxEditingStyle( SyntaxConstants.SYNTAX_STYLE_NONE );

  globalLanguageField = new SmartComboBox( new DefaultComboBoxModel( getScriptEngineLanguages() ) );
  globalLanguageField.setRenderer( new QueryLanguageListCellRenderer() );
  globalLanguageField.addActionListener( new UpdateScriptLanguageHandler() );

  queryScriptTextArea = new RSyntaxTextArea();
  queryScriptTextArea.setSyntaxEditingStyle( SyntaxConstants.SYNTAX_STYLE_NONE );
  queryScriptTextArea.getDocument().addDocumentListener( new QueryScriptDocumentListener() );

  queryLanguageListCellRenderer = new QueryLanguageListCellRenderer();

  queryLanguageField = new SmartComboBox( new DefaultComboBoxModel( getScriptEngineLanguages() ) );
  queryLanguageField.setRenderer( queryLanguageListCellRenderer );
  queryLanguageField.addActionListener( new UpdateScriptLanguageHandler() );

  super.init();
}
 
Example 19
Source File: RouteTablePanel.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @see javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
 *      java.lang.Object, boolean, boolean, int, int)
 */
@Override
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row,
		final int column) {
	final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
	if (c instanceof JLabel) {
		final JLabel label = (JLabel) c;
		// bg selection color
		if (isSelected) {
			label.setBackground(new Color(200, 200, 255));
		} else {
			// otherwise, alternate bg color
			if (row % 2 == 0) {
				label.setBackground(new Color(245, 245, 245));
			} else {
				label.setBackground(new Color(254, 254, 254));
			}
		}
		final Column col = _indexToColumn.get(column);
		if (col == Column.COUNTRY_FLAG) {
			label.setText("");
			label.setIcon((ImageIcon) value);
		} else if (col == Column.WHO_IS) {
			final JButton button = new JButton("?");
			button.setMargin(new Insets(0, 0, 0, 0));
			if (Env.INSTANCE.getOs() == OS.win) {
				button.setBorder(null);
			}
			final RoutePoint point = _route.getRoute().get(row);
			button.setToolTipText(Column.WHO_IS.getLabel());
			button.setPreferredSize(new Dimension(Column.WHO_IS.getWidth(), c.getHeight()));
			button.setEnabled(!_searching && point != null && !point.isUnknown());
			return button;
		} else {
			if ((col == Column.LATENCY || col == Column.DNS_LOOKUP) && value.equals(0l)) {
				if (!_dnsLookup && col == Column.DNS_LOOKUP) {
					label.setText("");
				} else {
					label.setText("<1");
				}
			}
		}
		label.setToolTipText(label.getText());
	}
	c.setFont(Env.INSTANCE.getFont());
	return c;
}
 
Example 20
Source File: ClassPresenterPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void initComponents() {
    Color borderColor = UIManager.getLookAndFeel().getID().equals("Metal") ? // NOI18N
        UIManager.getColor("Button.darkShadow") : UIManager.getColor("Button.shadow"); // NOI18N
    setBorder(BorderFactory.createCompoundBorder(
        BorderFactory.createLineBorder(borderColor), BorderFactory.createEmptyBorder(2, 5, 2, 5)));
    setOpaque(true);
    setBackground(UIUtils.getDarker(UIUtils.getProfilerResultsBackground()));

    headerRenderer = new HeaderRenderer();
    headerRenderer.setIcon(ICON_CLASS);
    headerRenderer.setForeground(UIManager.getColor("ToolTip.foreground")); // NOI18N
    headerRenderer.setFont(UIManager.getFont("ToolTip.font")); // NOI18N
    headerRenderer.setOpaque(false);

    detailsRenderer = new JLabel();
    detailsRenderer.setForeground(UIManager.getColor("ToolTip.foreground")); // NOI18N
    detailsRenderer.setFont(UIManager.getFont("ToolTip.font")); // NOI18N
    detailsRenderer.setOpaque(false);
    
    actionsDivider = new JLabel("  |  "); // NOI18N
    actionsDivider.setForeground(UIManager.getColor("ToolTip.foreground")); // NOI18N
    actionsDivider.setFont(UIManager.getFont("ToolTip.font")); // NOI18N
    actionsDivider.setOpaque(false);

    actionsRenderer = new JButton() {
        protected void fireActionPerformed(ActionEvent e) {
            if (heapFragmentWalker != null) {
                BrowserUtils.performTask(new Runnable() {
                    public void run() {
                        heapFragmentWalker.computeRetainedSizes(true, true);
                    }
                });
            }
        }
        public Dimension getMinimumSize() {
            return getPreferredSize();
        }
        public Dimension getMaximumSize() {
            return getPreferredSize();
        }
        public void setVisible(boolean visible) {
            super.setVisible(visible);
            actionsDivider.setVisible(visible);
        }
        public boolean isContentAreaFilled() {
            return !UIUtils.isOracleLookAndFeel() ? false : isFocusOwner();
        }
        public boolean isOpaque() {
            return !UIUtils.isOracleLookAndFeel() ? false : isFocusOwner();
        }
    };
    actionsRenderer.setOpaque(false);
    actionsRenderer.setContentAreaFilled(false);
    actionsRenderer.setBorderPainted(true);
    actionsRenderer.setMargin(new Insets(0, 0, 0, 0));
    actionsRenderer.setBorder(BorderFactory.createEmptyBorder());
    actionsRenderer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    actionsRenderer.setFont(UIManager.getFont("ToolTip.font")); // NOI18N
    actionsRenderer.setText("<html><nobr><a href='#'>" + Bundle.ClassPresenterPanel_RetainedSizesString() + "</a></nobr></html>"); // NOI18N
    actionsRenderer.setVisible(false);

    JPanel detailsContainer = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
    detailsContainer.setOpaque(false);
    detailsContainer.add(detailsRenderer);
    detailsContainer.add(actionsDivider);
    detailsContainer.add(actionsRenderer);
    
    setLayout(new GridBagLayout());
    
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    add(headerRenderer, c);
    
    JPanel filler = new JPanel(null);
    filler.setOpaque(false);
    c = new GridBagConstraints();
    c.gridx = 1;
    c.weightx = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    add(filler, c);
    
    c = new GridBagConstraints();
    c.gridx = 2;
    add(detailsContainer, c);
}