Java Code Examples for javax.swing.JToggleButton#setPreferredSize()
The following examples show how to use
javax.swing.JToggleButton#setPreferredSize() .
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 |
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 |
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: TimerPanel.java From plugins with GNU General Public License v3.0 | 6 votes |
TimerPanel(ClockManager clockManager, Timer timer) { super(clockManager, timer, "timer", true); JToggleButton loopButton = new JToggleButton(ClockTabPanel.LOOP_ICON); loopButton.setRolloverIcon(ClockTabPanel.LOOP_ICON_HOVER); loopButton.setSelectedIcon(ClockTabPanel.LOOP_SELECTED_ICON); loopButton.setRolloverSelectedIcon(ClockTabPanel.LOOP_SELECTED_ICON_HOVER); SwingUtil.removeButtonDecorations(loopButton); loopButton.setPreferredSize(new Dimension(16, 14)); loopButton.setToolTipText("Loop timer"); loopButton.addActionListener(e -> timer.setLoop(!timer.isLoop())); loopButton.setSelected(timer.isLoop()); leftActions.add(loopButton); JButton deleteButton = new JButton(ClockTabPanel.DELETE_ICON); SwingUtil.removeButtonDecorations(deleteButton); deleteButton.setRolloverIcon(ClockTabPanel.DELETE_ICON_HOVER); deleteButton.setPreferredSize(new Dimension(16, 14)); deleteButton.setToolTipText("Delete timer"); deleteButton.addActionListener(e -> clockManager.removeTimer(timer)); rightActions.add(deleteButton); }
Example 4
Source File: JTSTestBuilderToolBar.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
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 5
Source File: FiltersManagerImpl.java From netbeans with Apache License 2.0 | 6 votes |
private JToggleButton createToggle(Map<String, Boolean> fStates, int index) { boolean isSelected = filtersDesc.isSelected(index); boolean enabled = filtersDesc.isEnabled(index); Icon icon = filtersDesc.getIcon(index); // ensure small size, just for the icon JToggleButton result = new JToggleButton(icon, enabled && isSelected); Dimension size = new Dimension(21, 21); // 3 less than other buttons result.setMaximumSize(size); result.setMinimumSize(size); result.setPreferredSize(size); if ("Aqua".equals(UIManager.getLookAndFeel().getID())) { //NOI18N result.setBorderPainted(true); } else { result.setBorderPainted(false); } // result.setMargin(new Insets(2, 3, 2, 3)); result.setToolTipText(filtersDesc.getTooltip(index)); result.setEnabled(enabled); fStates.put(filtersDesc.getKey(index), Boolean.valueOf(isSelected)); return result; }
Example 6
Source File: VariablesViewButtons.java From netbeans with Apache License 2.0 | 6 votes |
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 7
Source File: BreakpointsViewButtons.java From netbeans with Apache License 2.0 | 6 votes |
@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 8
Source File: TimerPanel.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
TimerPanel(ClockManager clockManager, Timer timer) { super(clockManager, timer, "timer", true); JToggleButton loopButton = new JToggleButton(ClockTabPanel.LOOP_ICON); loopButton.setRolloverIcon(ClockTabPanel.LOOP_ICON_HOVER); loopButton.setSelectedIcon(ClockTabPanel.LOOP_SELECTED_ICON); loopButton.setRolloverSelectedIcon(ClockTabPanel.LOOP_SELECTED_ICON_HOVER); SwingUtil.removeButtonDecorations(loopButton); loopButton.setPreferredSize(new Dimension(16, 14)); loopButton.setToolTipText("Loop timer"); loopButton.addActionListener(e -> timer.setLoop(!timer.isLoop())); loopButton.setSelected(timer.isLoop()); leftActions.add(loopButton); JButton deleteButton = new JButton(ClockTabPanel.DELETE_ICON); SwingUtil.removeButtonDecorations(deleteButton); deleteButton.setRolloverIcon(ClockTabPanel.DELETE_ICON_HOVER); deleteButton.setPreferredSize(new Dimension(16, 14)); deleteButton.setToolTipText("Delete timer"); deleteButton.addActionListener(e -> clockManager.removeTimer(timer)); rightActions.add(deleteButton); }
Example 9
Source File: Compass.java From jclic with GNU General Public License v2.0 | 5 votes |
/** Creates new Compass */ public Compass() { super(new java.awt.GridLayout(3, 3)); setOpaque(false); direction = -1; ActionListener lst = new ActionListener() { public void actionPerformed(ActionEvent ev) { String c = ev.getActionCommand(); for (int i = 0; i < 9; i++) { if (BT_NAMES[i].equals(c)) { setDirection(i); break; } } } }; ButtonGroup bg = new ButtonGroup(); buttons = new JToggleButton[9]; for (int i = 0; i < 9; i++) { JToggleButton btn = new JToggleButton( new ImageIcon(getClass().getResource("/edu/xtec/resources/icons/" + BT_NAMES[i] + ".gif"))); btn.setPreferredSize(BT_DIMENSION); bg.add(btn); btn.setActionCommand(BT_NAMES[i]); btn.addActionListener(lst); btn.setFocusPainted(false); add(btn); buttons[i] = btn; } }
Example 10
Source File: TabSelector.java From magarena with GNU General Public License v3.0 | 5 votes |
public void addTab(MagicPlayerZone zone, int player) { final JToggleButton button = new JToggleButton(); button.setToolTipText(null); button.setBackground(this.backgroundColor); button.setFocusable(false); button.setPreferredSize(buttonDimension); button.setActionCommand(zone.name() + DELIM + player + DELIM + buttons.size()); button.addActionListener(this); buttons.add(button); buttonPanel.add(button); if (buttons.size() == 1) { showTab(button); } }
Example 11
Source File: MainMenuPanel.java From settlers-remake with MIT License | 5 votes |
private void registerMenu(String translationKey, ActionListener listener) { JToggleButton bt = new JToggleButton(Labels.getString(translationKey)); bt.putClientProperty(ELFStyle.KEY, ELFStyle.BUTTON_MENU); buttonGroup.add(bt); bt.addActionListener(listener); buttonPanel.add(bt); bt.setPreferredSize(new Dimension(230, 60)); }
Example 12
Source File: Desing$CodeSwitcherPane.java From DroidUIBuilder with Apache License 2.0 | 5 votes |
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 13
Source File: ToggleButtonGroup.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
/** * Creates a new button group from the given Actions (requires at least two actions). * * @param preferredSize * the preferredSize of the nested {@link CompositeToggleButton}s or {@code null} * @param actions * the action */ public ToggleButtonGroup(Dimension preferredSize, Action... actions) { if (actions.length < 2) { throw new IllegalArgumentException("At least two primary actions must be specified."); } this.setOpaque(false); this.preferredSize = preferredSize; primaryButtons = new CompositeToggleButton[actions.length]; for (int i = 0; i < actions.length; i++) { int position; if (i == 0) { position = SwingConstants.LEFT; } else if (i < actions.length - 1) { position = SwingConstants.CENTER; } else { position = SwingConstants.RIGHT; } primaryButtons[i] = new CompositeToggleButton(actions[i], position); } // align buttons left to right with no padding GridBagLayout layout = new GridBagLayout(); setLayout(layout); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 0, 0); gbc.fill = GridBagConstraints.VERTICAL; gbc.weighty = 1; for (JToggleButton button : primaryButtons) { button.addActionListener(buttonChooser); if (preferredSize != null) { button.setMinimumSize(preferredSize); button.setPreferredSize(preferredSize); } add(button, gbc); } }
Example 14
Source File: Controler.java From brModelo with GNU General Public License v3.0 | 5 votes |
private JToggleButton arrume(JToggleButton btn) { Dimension btnDim = new Dimension(40, 40); btn.setHideActionText(true); btn.setFocusable(false); btn.setPreferredSize(btnDim); btn.setDoubleBuffered(true); //btn.setMargin(new Insets(2, 5, 2, 5)); btn.setRolloverEnabled(false); return btn; }
Example 15
Source File: FiltersManager.java From netbeans with Apache License 2.0 | 5 votes |
private JToggleButton createToggle (Map fStates, int index) { boolean isSelected = filtersDesc.isSelected(index); Icon icon = filtersDesc.getSelectedIcon(index); // ensure small size, just for the icon JToggleButton result = new JToggleButton(icon, isSelected); Dimension size = new Dimension(icon.getIconWidth() + 6, icon.getIconHeight() + 4); result.setPreferredSize(size); result.setMargin(new Insets(2,3,2,3)); result.setToolTipText(filtersDesc.getTooltip(index)); fStates.put(filtersDesc.getName(index), Boolean.valueOf(isSelected)); return result; }
Example 16
Source File: FiltersManager.java From netbeans with Apache License 2.0 | 5 votes |
private JToggleButton createToggle (Map<String,Boolean> fStates, int index) { boolean isSelected = filtersDesc.isSelected(index); Icon icon = filtersDesc.getSelectedIcon(index); // ensure small size, just for the icon JToggleButton result = new JToggleButton(icon, isSelected); Dimension size = new Dimension(icon.getIconWidth() + 6, icon.getIconHeight() + 4); result.setPreferredSize(size); result.setMargin(new Insets(2,3,2,3)); result.setToolTipText(filtersDesc.getTooltip(index)); fStates.put(filtersDesc.getName(index), Boolean.valueOf(isSelected)); return result; }
Example 17
Source File: FiltersManagerImpl.java From netbeans with Apache License 2.0 | 5 votes |
private void addAdditionalButtons(JToggleButton[] sortButtons) { Dimension space = new Dimension(3, 0); for (JToggleButton button : sortButtons) { Dimension size = new Dimension(21, 21); // 3 less than other buttons button.setMaximumSize(size); button.setMinimumSize(size); button.setPreferredSize(size); // button.setMargin(new Insets(2, 3, 2, 3)); toolbar.addSeparator(space); toolbar.add(button); } }
Example 18
Source File: FiltersManager.java From netbeans with Apache License 2.0 | 5 votes |
private JToggleButton createToggle (Map<String,Boolean> fStates, int index) { boolean isSelected = getPreferences().getBoolean( filtersDesc.getName(index), filtersDesc.isSelected(index) ); Icon icon = filtersDesc.getSelectedIcon(index); // ensure small size, just for the icon JToggleButton result = new JToggleButton(icon, isSelected); Dimension size = new Dimension(icon.getIconWidth() + 6, icon.getIconHeight() + 4); result.setPreferredSize(size); result.setMargin(new Insets(2,3,2,3)); result.setToolTipText(filtersDesc.getTooltip(index)); result.setFocusable(false); fStates.put(filtersDesc.getName(index), Boolean.valueOf(isSelected)); return result; }