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

The following examples show how to use javax.swing.JToggleButton#setIcon() . 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: ToolBarManager.java    From openAGV with Apache License 2.0 6 votes vote down vote up
/**
   * Method addSelectionToolButton must have been invoked prior to this on the
   * JToolBar.
   *
   * @param toolBar
   * @param editor
   * @param tool
   * @param toolTipText
   * @param labels
   * @return
   */
  private JToggleButton addToolButton(JToolBar toolBar,
                                      DrawingEditor editor,
                                      Tool tool,
                                      String toolTipText,
                                      ImageIcon iconBase) {
    JToggleButton toggleButton = new JToggleButton();

    toggleButton.setIcon(iconBase);
    toggleButton.setText(null);
    toggleButton.setToolTipText(toolTipText);
    toggleButton.addItemListener(new ToolButtonListener(tool, editor));
//    toggleButton.setFocusable(false);

    ToolListener toolHandler = (ToolListener) toolBar.getClientProperty("toolHandler");
    tool.addToolListener(toolHandler);

    ButtonGroup group = (ButtonGroup) toolBar.getClientProperty("toolButtonGroup");
    group.add(toggleButton);
    toolBar.add(toggleButton);

    return toggleButton;
  }
 
Example 2
Source File: DrawingViewPlacardPanel.java    From openAGV with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a button to toggle the grid in the drawing.
 *
 * @param view The DrawingView the button will belong to.
 * @return The created button.
 */
private JToggleButton toggleConstrainerButton(final OpenTCSDrawingView drawingView) {
  final JToggleButton toggleButton = new JToggleButton();

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

  toggleButton.setIcon(ImageDirectory.getImageIcon("/menu/view-split.png"));

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

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

  return toggleButton;
}
 
Example 3
Source File: DrawingViewPlacardPanel.java    From openAGV with 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 4
Source File: DrawingViewPlacardPanel.java    From openAGV with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a button to toggle the blocks in the drawing.
 *
 * @param view The DrawingView the button will belong to.
 * @return The created button.
 */
private JToggleButton toggleBlocksButton(final OpenTCSDrawingView drawingView) {
  final JToggleButton toggleButton = new JToggleButton();

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

  toggleButton.setIcon(ImageDirectory.getImageIcon("/tree/block.18x18.png"));

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

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

  return toggleButton;
}
 
Example 5
Source File: JTSTestBuilderToolBar.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
private JToggleButton createToggleButton(String toolTipText, 
    ImageIcon icon, 
    java.awt.event.ActionListener actionListener)
{
  JToggleButton btn = new JToggleButton();
  btn.setMargin(new Insets(0, 0, 0, 0));
  btn.setPreferredSize(new Dimension(30, 30));
  btn.setIcon(icon);
  btn.setMinimumSize(new Dimension(30, 30));
  btn.setVerticalTextPosition(SwingConstants.BOTTOM);
  btn.setSelected(false);
  btn.setToolTipText(toolTipText);
  btn.setHorizontalTextPosition(SwingConstants.CENTER);
  btn.setFont(new java.awt.Font("SansSerif", 0, 10));
  btn.setMaximumSize(new Dimension(30, 30));
  btn.addActionListener(actionListener);
  return btn;
}
 
Example 6
Source File: SeaGlassDesktopIconUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getSource() instanceof JInternalFrame.JDesktopIcon) {
        if (SeaGlassLookAndFeel.shouldUpdateStyle(evt)) {
            updateStyle((JInternalFrame.JDesktopIcon) evt.getSource());
        }
    } else if (evt.getSource() instanceof JInternalFrame) {
        JInternalFrame frame = (JInternalFrame) evt.getSource();
        if (iconPane instanceof JToggleButton) {
            JToggleButton button = (JToggleButton) iconPane;
            String prop = evt.getPropertyName();
            if (prop == "title") {
                button.setText((String) evt.getNewValue());
            } else if (prop == "frameIcon") {
                button.setIcon((Icon) evt.getNewValue());
            } else if (prop == JInternalFrame.IS_ICON_PROPERTY || prop == JInternalFrame.IS_SELECTED_PROPERTY) {
                button.setSelected(!frame.isIcon() && frame.isSelected());
            }
        }
    }
}
 
Example 7
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 8
Source File: PressedIconTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void createAndShowGUI() {
    frame = new JFrame();
    frame.setSize(IMAGE_SIZE, IMAGE_SIZE);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel(new BorderLayout());

    BufferedImage img1x = generateImage(1, COLOR_1X);

    BufferedImage img2x = generateImage(2, COLOR_2X);
    BaseMultiResolutionImage mri = new BaseMultiResolutionImage(
            new BufferedImage[]{img1x, img2x});
    Icon mrIcon = new ImageIcon(mri);

    JToggleButton button = new JToggleButton();
    button.setIcon(mrIcon);
    panel.add(button, BorderLayout.CENTER);

    frame.getContentPane().add(panel);
    frame.setVisible(true);
}
 
Example 9
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 10
Source File: ToolBarManager.java    From openAGV with Apache License 2.0 5 votes vote down vote up
/**
   *
   * @param toolBar
   * @param editor
   */
  private JToggleButton addDragToolButton(JToolBar toolBar, DrawingEditor editor) {
    final JToggleButton button = new JToggleButton();
    dragTool = new DragTool();
    editor.setTool(dragTool);

    if (!(toolBar.getClientProperty("toolHandler") instanceof ToolListener)) {
      ToolListener toolHandler = new ToolAdapter() {
        @Override
        public void toolDone(ToolEvent event) {
          button.setSelected(true);
        }
      };
      toolBar.putClientProperty("toolHandler", toolHandler);
    }

    URL url = getClass().getResource(ImageDirectory.DIR + "/toolbar/cursor-opened-hand.png");
    button.setIcon(new ImageIcon(url));
    button.setText(null);
    button.setToolTipText(ResourceBundleUtil.getBundle(I18nPlantOverview.TOOLBAR_PATH)
        .getString("toolBarManager.button_dragTool.tooltipText"));

    button.setSelected(false);
    button.addItemListener(new ToolButtonListener(dragTool, editor));
//    button.setFocusable(false);

    ButtonGroup group = (ButtonGroup) toolBar.getClientProperty("toolButtonGroup");
    group.add(button);
    toolBar.add(button);
    return button;
  }
 
Example 11
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 12
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 13
Source File: BoardEditor.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets up JToggleButtons
 */
private JToggleButton addTerrainTButton(String iconName, String buttonName, ArrayList<JToggleButton> bList) {
    JToggleButton button = new JToggleButton(buttonName);
    button.addActionListener(this);
    
    // 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.setToolTipText(Messages.getString("BoardEditor."+iconName+"TT")); //$NON-NLS-1$ //$NON-NLS-2$
    if (bList != null) bList.add(button);
    return button;
}
 
Example 14
Source File: ObjectRepo.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private JToggleButton create(String text) {
    JToggleButton togg = new JToggleButton();
    togg.setIcon(Utils.getIconByResourceName("/ui/resources/or/" + text.toLowerCase()));
    togg.setToolTipText(text);
    togg.setActionCommand(text);
    togg.addItemListener(ObjectRepo.this);
    bgroup.add(togg);
    return togg;
}
 
Example 15
Source File: ActionFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    JToggleButton toggleButton = new JToggleButton();
    toggleButtonRef = new WeakReference<>(toggleButton);
    toggleButton.putClientProperty("hideActionText", Boolean.TRUE); //NOI18N
    toggleButton.setIcon((Icon) getValue(SMALL_ICON));
    toggleButton.setAction(this); // this will make hard ref to button => check GC
    return toggleButton;
}
 
Example 16
Source File: CSSStylesSelectionPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Property Summary section.
 *
 * @return Property Summary panel.
 */
private JPanel initPropertyPane() {
    propertyPane = new PropertyPaneView();
    String valueTitle =  NbBundle.getMessage(CSSStylesSelectionPanel.class, "CSSStylesSelectionPanel.value"); // NOI18N
    propertyPane.setProperties(new Node.Property[] {
        new PropertySupport.ReadOnly<String>(MatchedPropertyNode.PROPERTY_VALUE, String.class, valueTitle, null) {
            @Override
            public String getValue() throws IllegalAccessException, InvocationTargetException {
                return null;
            }
        }
    });
    ExplorerManagerProviderPanel propertyPanePanel = new ExplorerManagerProviderPanel();
    propertyPanePanel.setLayout(new BorderLayout());
    propertyPanePanel.add(propertyPane, BorderLayout.CENTER);
    JPanel headerPanel = new JPanel();
    headerPanel.setLayout(new BorderLayout());
    JPanel titlePanel = new JPanel();
    titlePanel.setLayout(new BoxLayout(titlePanel, BoxLayout.X_AXIS));
    propertySummaryLabel = new JLabel();
    propertySummaryLabel.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
    propertySummaryLabel.setMinimumSize(new Dimension(0,0));
    titlePanel.add(propertySummaryLabel);
    titlePanel.add(Box.createHorizontalGlue());
    JToggleButton pseudoClassToggle = new JToggleButton();
    pseudoClassToggle.setFocusPainted(false);
    pseudoClassToggle.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/web/inspect/resources/elementStates.png", true)); // NOI18N
    pseudoClassToggle.setToolTipText(NbBundle.getMessage(CSSStylesSelectionPanel.class, "CSSStylesSelectionPanel.pseudoClasses")); // NOI18N
    CustomToolbar toolBar = new CustomToolbar();
    toolBar.addButton(pseudoClassToggle);
    titlePanel.add(toolBar);
    headerPanel.add(titlePanel, BorderLayout.PAGE_START);
    headerPanel.add(createPseudoClassPanel(pseudoClassToggle), BorderLayout.CENTER);
    propertyPanePanel.add(headerPanel, BorderLayout.PAGE_START);
    propertyPaneManager = propertyPanePanel.getExplorerManager();
    propertyPanePanel.setMinimumSize(new Dimension(0,0)); // allow shrinking in JSplitPane
    return propertyPanePanel;
}
 
Example 17
Source File: ToggleDebuggingAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    toggleButton = new JToggleButton();
    toggleButton.putClientProperty("hideActionText", Boolean.TRUE); //NOI18N
    toggleButton.setIcon((Icon) getValue(SMALL_ICON));
    toggleButton.setAction(this); // this will make hard ref to button => check GC
    return toggleButton;
}
 
Example 18
Source File: DrawingViewPlacardPanel.java    From openAGV with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a button to toggle the rulers in the drawing.
 *
 * @return The created button.
 */
private JToggleButton toggleRulersButton() {
  final JToggleButton toggleButton = new JToggleButton();

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

  toggleButton.setIcon(ImageDirectory.getImageIcon("/toolbar/document-page-setup.16x16.png"));

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

  return toggleButton;
}
 
Example 19
Source File: CollapsiblePanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public FilesPanel(VCSCommitPanel master, Map<String, VCSCommitFilter> filters, int preferedHeight)  {
    super(master, master.getModifier().getMessage(VCSCommitPanelModifier.BundleMessage.FILE_PANEL_TITLE), DEFAULT_DISPLAY_FILES);
    this.filters = filters;
    
    master.getCommitTable().labelFor(filesLabel);
    
    JComponent table = master.getCommitTable().getComponent();
    
    Mnemonics.setLocalizedText(filesLabel, getMessage("CTL_CommitForm_FilesToCommit"));         // NOI18N
    filesLabel.setMaximumSize(new Dimension(Integer.MAX_VALUE, filesLabel.getMaximumSize().height));
    
    table.setPreferredSize(new Dimension(0, preferedHeight));
    
    ButtonGroup bg = new ButtonGroup();
    toolbar = new JToolBar();
    toolbar.setFloatable(false);
    
    for (VCSCommitFilter filter : filters.values()) {
        
        JToggleButton tgb = new JToggleButton();
        tgb.setIcon(filter.getIcon()); 
        tgb.setToolTipText(filter.getTooltip()); 
        tgb.setFocusable(false);
        tgb.setSelected(filter.isSelected());
        tgb.addActionListener(this);                
        tgb.putClientProperty(TOOLBAR_FILTER, filter);
        bg.add(tgb);
        toolbar.add(tgb);
        
    }
    toolbar.setAlignmentX(LEFT_ALIGNMENT);        
    
    sectionPanel.add(toolbar);
    sectionPanel.add(table);
    sectionPanel.add(VCSCommitPanel.makeVerticalStrut(filesLabel, table, RELATED, sectionPanel));
    sectionPanel.add(filesLabel);
    
    sectionPanel.setAlignmentX(LEFT_ALIGNMENT);
    filesLabel.setAlignmentX(LEFT_ALIGNMENT);
    table.setAlignmentX(LEFT_ALIGNMENT);
}