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

The following examples show how to use javax.swing.JButton#addFocusListener() . 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: ConfigWindow.java    From rscplus with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds a new keybind to the GUI and settings and registers it to be checked when keypresses are
 * sent to the applet.
 *
 * @param panel Panel to add the keybind label and button to
 * @param labelText Text describing the keybind's function as shown to the user on the config
 *     window.
 * @param commandID Unique String matching an entry in the processKeybindCommand switch statement.
 * @param defaultModifier Default modifier value. This can be one of the enum values of
 *     KeybindSet.KeyModifier, eg KeyModifier.CTRL
 * @param defaultKeyValue Default key value. This should match up with a KeyEvent.VK_ value. Set
 *     to -1 to set the default as NONE
 */
private void addKeybindSet(
    JPanel panel,
    String labelText,
    String commandID,
    KeyModifier defaultModifier,
    int defaultKeyValue) {
  addKeybindLabel(panel, labelText);
  String buttonText = defaultModifier.toString() + " + " + KeyEvent.getKeyText(defaultKeyValue);
  if (defaultKeyValue == -1) buttonText = "NONE";
  JButton b = addKeybindButton(panel, buttonText);
  KeybindSet kbs = new KeybindSet(b, commandID, defaultModifier, defaultKeyValue);
  KeyboardHandler.keybindSetList.add(kbs);
  setKeybindButtonText(
      kbs); // Set the text of the keybind button now that it has been initialized properly
  b.addActionListener(this.clickListener);
  b.addKeyListener(this.rebindListener);
  b.addFocusListener(focusListener);
  b.setFocusable(false);

  // Default KeybindSet
  KeyboardHandler.defaultKeybindSetList.put(
      commandID, new KeybindSet(null, commandID, defaultModifier, defaultKeyValue));
}
 
Example 2
Source File: ViewElementFilename.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
public ViewElementFilename(RobotOverlord ro,StringEntity e) {
	super(ro);
	this.e=e;
	
	//this.setBorder(BorderFactory.createLineBorder(Color.RED));
			
	field = new JTextField(15);
	field.setEditable(false);
	field.setText(e.get());
	field.setMargin(new Insets(1,0,1,0));
	//pathAndFileName.setBorder(BorderFactory.createLoweredBevelBorder());
	
	JLabel label=new JLabel(e.getName(),JLabel.LEADING);
	label.setLabelFor(field);

	JButton choose = new JButton("...");
	choose.addActionListener(this);
	choose.setMargin(new Insets(0, 5, 0, 5));
	choose.addFocusListener(this);
	
	panel.setLayout(new GridBagLayout());

	GridBagConstraints gbc = new GridBagConstraints();
	gbc.weightx=0;
	gbc.gridy=0;
	gbc.fill = GridBagConstraints.HORIZONTAL;
	//gbc.gridheight = GridBagConstraints.REMAINDER;
	gbc.insets.right=5;
	panel.add(label,gbc);
	gbc.weightx=1;
	gbc.insets.left=0;
	gbc.insets.right=0;
	panel.add(field,gbc);
	gbc.weightx=0;
	panel.add(choose,gbc);
}
 
Example 3
Source File: ViewElementButton.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
public ViewElementButton(RobotOverlord ro,String label) {
	super(ro);
	
	field = new JButton(label);
	field.addActionListener(this);
	field.addFocusListener(this);
	
	panel.setLayout(new BorderLayout());
	panel.add(field,BorderLayout.CENTER);
}
 
Example 4
Source File: ViewElementRemote.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
public ViewElementRemote(RobotOverlord ro,OneLineAtATimeRemoteEntity e) {
	super(ro);
	this.e=e;
	
	field = new JButton(e.isConnectionOpen()?Translator.get("Close"):Translator.get("Connect"));
	field.addActionListener(this);
	field.addFocusListener(this);
	panel.setLayout(new BorderLayout());
	panel.add(field,BorderLayout.CENTER);
}
 
Example 5
Source File: AbstractModalDialog.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
protected final JButton buildDialogButton(String buttonText) {
    JButton button = new JButton(buttonText);
    button.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent event) {
            getJDialog().requestFocusInWindow();
        }
    });
    Dimension size = button.getPreferredSize();
    size.width = 75;
    button.setPreferredSize(size);
    return button;
}
 
Example 6
Source File: JTagsDialog.java    From jeveassets with GNU General Public License v2.0 4 votes vote down vote up
public JTagsDialog(Program program) {
	super(program, "", Images.TAG_GRAY.getImage());

	ListenerClass listener = new ListenerClass();

	JLabel jLabel = new JLabel(GuiShared.get().tagsNewMsg());

	jTextField = new JTextField();
	jTextField.addFocusListener(listener);
	jTextField.addCaretListener(listener);

	jColor = new JButton();

	colorPicker = new ColorPicker(getDialog(), jColor);
	jColor.addFocusListener(listener);
	jColor.setActionCommand(TagsDialogAction.SHOW_COLOR.name());
	jColor.addActionListener(listener);

	jOK = new JButton(GuiShared.get().ok());
	jOK.setActionCommand(TagsDialogAction.OK.name());
	jOK.addActionListener(listener);
	jOK.addFocusListener(listener);

	JButton jCancel = new JButton(GuiShared.get().cancel());
	jCancel.setActionCommand(TagsDialogAction.CANCEL.name());
	jCancel.addActionListener(listener);
	jCancel.addFocusListener(listener);

	layout.setHorizontalGroup(
		layout.createParallelGroup(GroupLayout.Alignment.CENTER)
			.addComponent(jLabel, 250, 250, Integer.MAX_VALUE)
			.addGroup(layout.createSequentialGroup()
				.addComponent(jTextField, 200, 200, 200)
				.addComponent(jColor, 30, 30, 30)
			)
			.addGroup(layout.createSequentialGroup()
				.addComponent(jOK, Program.getButtonsWidth(), Program.getButtonsWidth(), Program.getButtonsWidth())
				.addComponent(jCancel, Program.getButtonsWidth(), Program.getButtonsWidth(), Program.getButtonsWidth())
			)
	);
	layout.setVerticalGroup(
		layout.createSequentialGroup()
			.addComponent(jLabel, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
			.addGroup(layout.createParallelGroup()
				.addComponent(jTextField, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
				.addComponent(jColor, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
			)
			.addGroup(layout.createParallelGroup()
				.addComponent(jOK, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
				.addComponent(jCancel, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight())
			)
	);
}