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

The following examples show how to use javax.swing.JToggleButton#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: VariablesViewButtons.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static JToggleButton createToggleButton (final String id, String iconPath, String tooltip) {
    Icon icon = ImageUtilities.loadImageIcon(iconPath, false);
    boolean isSelected = isButtonSelected(id);
    final JToggleButton toggleButton = new JToggleButton(icon, isSelected);
    // ensure small size, just for the icon
    Dimension size = new Dimension(icon.getIconWidth() + 8, icon.getIconHeight() + 8);
    toggleButton.setPreferredSize(size);
    toggleButton.setMargin(new Insets(1, 1, 1, 1));
    if (!"Aqua".equals(UIManager.getLookAndFeel().getID())) { //NOI18N
        // We do not want an ugly border with the exception of Mac, where it paints the toggle state!
        toggleButton.setBorder(new EmptyBorder(toggleButton.getBorder().getBorderInsets(toggleButton)));
    }
    toggleButton.setToolTipText(tooltip);
    toggleButton.setFocusable(false);
    return toggleButton;
}
 
Example 2
Source File: VariablesViewButtons.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static JToggleButton createToggleButton (final String id, String iconName, String tooltip) {
    Icon icon = loadIcon(iconName);
    boolean isSelected = isButtonSelected(id);
    final JToggleButton toggleButton = new JToggleButton(icon, isSelected);
    // ensure small size, just for the icon
    Dimension size = new Dimension(icon.getIconWidth() + 8, icon.getIconHeight() + 8);
    toggleButton.setPreferredSize(size);
    toggleButton.setMargin(new Insets(1, 1, 1, 1));
    if (!"Aqua".equals(UIManager.getLookAndFeel().getID())) { //NOI18N
        // We do not want an ugly border with the exception of Mac, where it paints the toggle state!
        toggleButton.setBorder(new EmptyBorder(toggleButton.getBorder().getBorderInsets(toggleButton)));
    }
    toggleButton.setToolTipText(tooltip);
    toggleButton.setFocusable(false);
    return toggleButton;
}
 
Example 3
Source File: VariablesViewButtons.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static JToggleButton createToggleButton (final String id, String iconName, String tooltip) {
    Icon icon = loadIcon(iconName);
    boolean isSelected = isButtonSelected(id);
    final JToggleButton toggleButton = new JToggleButton(icon, isSelected);
    // ensure small size, just for the icon
    Dimension size = new Dimension(icon.getIconWidth() + 8, icon.getIconHeight() + 8);
    toggleButton.setPreferredSize(size);
    toggleButton.setMargin(new Insets(1, 1, 1, 1));
    if (!"Aqua".equals(UIManager.getLookAndFeel().getID())) { //NOI18N
        // We do not want an ugly border with the exception of Mac, where it paints the toggle state!
        toggleButton.setBorder(new EmptyBorder(toggleButton.getBorder().getBorderInsets(toggleButton)));
    }
    toggleButton.setToolTipText(tooltip);
    toggleButton.setFocusable(false);
    return toggleButton;
}
 
Example 4
Source File: BreakpointsViewButtons.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NbBundle.Messages({"CTL_DeactivateAllBreakpoints=Deactivate all breakpoints in current session",
                    "CTL_ActivateAllBreakpoints=Activate all breakpoints in current session",
                    "CTL_NoDeactivation=The current session does not allow to deactivate breakpoints",
                    "CTL_NoSession=No debugger session"})
public static AbstractButton createActivateBreakpointsActionButton() {
    ImageIcon icon = ImageUtilities.loadImageIcon(DEACTIVATED_LINE_BREAKPOINT, false);
    final JToggleButton button = new JToggleButton(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(Bundle.CTL_DeactivateAllBreakpoints());
    button.setFocusable(false);
    final BreakpointsActivator ba = new BreakpointsActivator(button);
    button.addActionListener(ba);
    DebuggerManager.getDebuggerManager().addDebuggerListener(DebuggerManager.PROP_CURRENT_ENGINE, new DebuggerManagerAdapter() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            DebuggerEngine de = (DebuggerEngine) evt.getNewValue();
            ba.setCurrentEngine(de);
        }
    });
    ba.setCurrentEngine(DebuggerManager.getDebuggerManager().getCurrentEngine());
    return button;
}
 
Example 5
Source File: IconPanel.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@Nonnull
private JToggleButton makeIconButton(@Nonnull final ButtonGroup group, @Nonnull final String name) {
  final JToggleButton result = Utils.UI_COMPO_FACTORY.makeToggleButton();

  final Color panelColor = this.getBackground();

  result.setUI(new MetalToggleButtonUI() {
    @Override
    @Nullable
    protected Color getSelectColor() {
      return panelColor.brighter();
    }
  });

  result.setBackground(panelColor.darker());

  result.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), BorderFactory.createEmptyBorder(3, 3, 3, 3)));
  result.setIcon(new ImageIcon(MiscIcons.findForName(name)));
  result.setName(name);
  result.setFocusPainted(false);
  result.setToolTipText(name);

  group.add(result);
  return result;
}
 
Example 6
Source File: PaletteUI.java    From pumpernickel with MIT License 5 votes vote down vote up
private JToggleButton createCell() {
	JToggleButton newCell = new JToggleButton();
	newCell.addMouseListener(mouseListener);
	newCell.addMouseMotionListener(mouseListener);
	newCell.setContentAreaFilled(false);
	newCell.setBorder(null);
	newCell.setRequestFocusEnabled(false);
	newCell.setBorderPainted(false);
	newCell.setOpaque(false);
	newCell.putClientProperty(PROPERTY_CELL, Boolean.TRUE);
	newCell.addActionListener(cellActionListener);
	return newCell;
}
 
Example 7
Source File: ExitsDialog.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets up JToggleButtons
 */
JToggleButton setupTButton(String iconName, String buttonName) {
    JToggleButton button = new JToggleButton(buttonName);

    // Get the normal icon
    File file = new MegaMekFile(Configuration.widgetsDir(), "/MapEditor/"+iconName+".png").getFile(); //$NON-NLS-1$ //$NON-NLS-2$
    Image imageButton = ImageUtil.loadImageFromFile(file.getAbsolutePath());
    if (imageButton != null) {
        button.setIcon(new ImageIcon(imageButton));
        // When there is an icon, then the text can be removed
        button.setText("");
    }

    // Get the hover icon
    file = new MegaMekFile(Configuration.widgetsDir(), "/MapEditor/"+iconName+"_H.png").getFile(); //$NON-NLS-1$ //$NON-NLS-2$
    imageButton = ImageUtil.loadImageFromFile(file.getAbsolutePath());
    if (imageButton != null)
        button.setRolloverIcon(new ImageIcon(imageButton));

    // Get the selected icon
    file = new MegaMekFile(Configuration.widgetsDir(), "/MapEditor/"+iconName+"_S.png").getFile(); //$NON-NLS-1$ //$NON-NLS-2$
    imageButton = ImageUtil.loadImageFromFile(file.getAbsolutePath());
    if (imageButton != null)
        button.setSelectedIcon(new ImageIcon(imageButton));

    button.setMargin(new Insets(0,0,0,0));
    button.setBorder(BorderFactory.createEmptyBorder());
    
    return button;
}
 
Example 8
Source File: Desing$CodeSwitcherPane.java    From DroidUIBuilder with Apache License 2.0 5 votes vote down vote up
private void initGUI()
{
	// 实例化按钮
	ButtonGroup bg = new ButtonGroup();
	btnLeft = new JToggleButton("");
	btnRight = new JToggleButton("");
	btnLeft.setContentAreaFilled(false);
	btnLeft.setFocusable(false);
	btnLeft.setBorder(null);
	btnLeft.setPreferredSize(new Dimension(64,25));
	btnRight.setContentAreaFilled(false);
	btnRight.setFocusable(false);
	btnRight.setBorder(null);
	btnRight.setPreferredSize(new Dimension(64,25));
	
	// 加入到ButtonGroup(实现RadioButton的形为)
	bg.add(btnLeft);
	bg.add(btnRight);
	
	// 主面板布局
	FlowLayout mainLayout = new FlowLayout(FlowLayout.CENTER);
	mainLayout.setHgap(0);
	mainLayout.setVgap(2);
	this.setLayout(mainLayout);
	// 此处的border的设置是为了背景上部的装饰而做哦
	this.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
	
	// 实例化按钮面板
	btnPane = new BtnPane();
	btnPane.add(btnLeft);
	btnPane.add(btnRight);
	
	// 添加到总体布局中
	this.add(btnPane);
}
 
Example 9
Source File: DivergingColorPalettePanel.java    From colorbrewer with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected JToggleButton createPalette(ColorBrewer brewer, Border normalBorder) {
	JToggleButton palette = new JToggleButton();
	palette.setActionCommand(brewer.name());
	palette.addActionListener(this);
	Icon icon = new PaletteIcon(brewer, 5, 15, 15);
	palette.setIcon(icon);
	palette.setToolTipText(brewer.getPaletteDescription());
	palette.setBorder(normalBorder);
	return palette;
}
 
Example 10
Source File: QualitativeColorPalettePanel.java    From colorbrewer with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected JToggleButton createPalette(ColorBrewer brewer, Border normalBorder) {
	JToggleButton palette = new JToggleButton();
	palette.setActionCommand(brewer.name());
	palette.addActionListener(this);
	Icon icon = new PaletteIcon(brewer, 5, 15, 15);
	palette.setIcon(icon);
	palette.setToolTipText(brewer.getPaletteDescription());
	palette.setBorder(normalBorder);
	return palette;
}
 
Example 11
Source File: CrossWord.java    From jclic with GNU General Public License v2.0 5 votes vote down vote up
private BoxBag createBoxBag(int n) {
  BoxBag bxb = new BoxBag(null, this, null);
  SimpleBox sb = new SimpleBox(bxb, null, null);
  sb.setBounds(0, 0, LABEL_WIDTH, abc[n].h);
  sb.setBorder(true);
  JToggleButton tgbtn = new JToggleButton(
      edu.xtec.util.ResourceManager.getImageIcon(n == 0 ? "buttons/textright.png" : "buttons/textdown.png"));
  tgbtn.addActionListener(this);
  javax.swing.border.Border border = tgbtn.getBorder();
  sb.setHostedComponent(tgbtn);
  tgbtn.setBorder(border);
  bxb.addBox(sb);

  ActiveBox ab = new ActiveBox(bxb, null, n,
      new java.awt.geom.Rectangle2D.Double(LABEL_WIDTH, 0, abc[n].w, abc[n].h), null);
  bxb.addBox(ab);
  bxb.setBoxBase(abc[n].bb);

  if (n == 0) {
    hClue = ab;
    hClueBtn = tgbtn;
  } else {
    vClue = ab;
    vClueBtn = tgbtn;
  }
  return bxb;
}
 
Example 12
Source File: CssStylesPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void updateToolbar(FileObject file, Collection<CssStylesPanelProvider> activeProviders) {

        toolBar.removeAll();
        if (activeProviders.size() <= 1) {
            //remove the whole toolbar, if there's one or zero providers
            removeToolbar();
        } else {
            addToolbar();
        }

        // Button group for document and source buttons
        ButtonGroup buttonGroup = new ButtonGroup();

        boolean first = true;

        CssStylesPanelProvider selected = (file == null) ? null : selectedTabs.get(file.getMIMEType());

        //do the active providers contain the pre-selected provider for this mimetype?
        boolean containsPreselected = selected == null ? false : activeProviders.contains(selected);

        for (CssStylesPanelProvider provider : activeProviders) {
            JToggleButton button = new JToggleButton();
            button.setText(provider.getPanelDisplayName());
            button.setActionCommand(provider.getPanelID());
            button.addActionListener(toolbarListener);

            button.setFocusable(true);
            button.setFocusPainted(false);
            button.setRolloverEnabled(true);

            //copied from org.netbeans.core.multiview.TabsComponent.createButton to make the look 
            //similar to the editor tabs
            Border b = (getButtonBorder());
            if (b != null) {
                button.setBorder(b);
            }
            if (AQUA) {
                button.putClientProperty("JButton.buttonType", "square"); //NOI18N
                button.putClientProperty("JComponent.sizeVariant", "small"); //NOI18N
            }

            buttonGroup.add(button);
            toolBar.add(button);

            if (containsPreselected) {
                //one of the active providers is already pre-selected by user
                if (provider == selected) {
                    //the selected one - activate it
                    button.setSelected(true);
                    setActiveProvider(provider);
                } else {
                    button.setSelected(false);
                }
            } else {
                //no provider has been explicitly selected by the user yet
                button.setSelected(first);
                if (first) {
                    setActiveProvider(provider);
                    first = false;
                }
            }
        }

        revalidate();
        repaint();
    }
 
Example 13
Source File: MapEditorTransformPanel.java    From freecol with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Builds the button for the given terrain.
 *
 * @param image an {@code Image} value
 * @param text a {@code String} value
 * @param mt a {@code MapTransform} value
 * @return A suitable button.
 */
private JToggleButton buildButton(Image image, String text,
                                  final MapTransform mt) {
    final MapEditorController ctlr
        = getFreeColClient().getMapEditorController();
    JPanel descriptionPanel = new JPanel(new BorderLayout());
    descriptionPanel.add(new JLabel(new ImageIcon(image)),
                         BorderLayout.CENTER);
    descriptionPanel.add(new JLabel(text, JLabel.CENTER),
            BorderLayout.PAGE_END);
    descriptionPanel.setBackground(Color.RED);
    mt.setDescriptionPanel(descriptionPanel);

    ImageIcon icon = new ImageIcon(image);
    final JToggleButton button = new JToggleButton(icon);
    button.setToolTipText(text);
    button.setOpaque(false);
    group.add(button);
    button.addActionListener((ActionEvent ae) -> {
            MapTransform newMapTransform = null;
            if (ctlr.getMapTransform() != mt) {
                if (mt instanceof RiverStyleTransform) {
                    RiverStyleTransform rst = (RiverStyleTransform)mt;
                    boolean all = rst.getType() != RiverStyleTransform.CHANGE_CONNECTIONS;
                    String style = getGUI()
                        .showRiverStyleDialog(ImageLibrary
                            .getRiverStyleKeys(all));
                    if (style != null) rst.setStyle(style);
                }
                newMapTransform = mt;
            }
            ctlr.setMapTransform(newMapTransform);
            if (newMapTransform == null && mt != null) {
                // Select the invisible button, de-selecting all others
                group.setSelected(group.getElements().nextElement()
                    .getModel(), true);
            }
        });
    button.setBorder(null);
    return button;
}