javax.swing.JButton#addFocusListener ( )源码实例Demo

下面列出了javax.swing.JButton#addFocusListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: rscplus   文件: ConfigWindow.java
/**
 * 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));
}
 
源代码2 项目: Robot-Overlord-App   文件: ViewElementFilename.java
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);
}
 
源代码3 项目: Robot-Overlord-App   文件: ViewElementButton.java
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);
}
 
源代码4 项目: Robot-Overlord-App   文件: ViewElementRemote.java
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);
}
 
源代码5 项目: snap-desktop   文件: AbstractModalDialog.java
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;
}
 
源代码6 项目: jeveassets   文件: JTagsDialog.java
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())
			)
	);
}