Search in sources :

Example 31 with FocusAdapter

use of java.awt.event.FocusAdapter in project n2a by frothga.

the class SettingsGeneral method addField.

public JPanel addField(final String key, String description, int width, String defaultValue) {
    JLabel label = new JLabel(description);
    String value = AppData.state.getOrDefault("General", key, defaultValue);
    final JTextField field = new JTextField(value, width);
    field.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent arg0) {
            AppData.state.set("General", key, field.getText());
        }
    });
    field.addFocusListener(new FocusAdapter() {

        public void focusLost(FocusEvent e) {
            AppData.state.set("General", key, field.getText());
        }
    });
    return Lay.FL("H", label, field);
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) FocusEvent(java.awt.event.FocusEvent)

Example 32 with FocusAdapter

use of java.awt.event.FocusAdapter in project n2a by frothga.

the class Lay method tx.

public static JTextField tx(Object text, Object... args) {
    HintList hints = new HintList();
    for (Object arg : args) {
        if (arg instanceof String) {
            hints.addHints(parseHints((String) arg));
        }
    }
    final JTextField txt = new JTextField("" + text);
    if (hints.contains("selectall")) {
        txt.addFocusListener(new FocusAdapter() {

            @Override
            public void focusGained(FocusEvent e) {
                txt.selectAll();
            }
        });
    }
    setHints(txt, hints);
    return txt;
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) JTextField(javax.swing.JTextField) FocusEvent(java.awt.event.FocusEvent)

Example 33 with FocusAdapter

use of java.awt.event.FocusAdapter in project knime-core by knime.

the class VariableFileReaderNodeDialog method createFileNamePanel.

private JPanel createFileNamePanel() {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Select variable holding file location: (press 'Enter' to " + "update preview)"));
    Box fileBox = Box.createHorizontalBox();
    // Creating the brows button here in order to get its preferred height
    int buttonHeight = 20;
    m_urlCombo = new JComboBox();
    m_urlCombo.setEditable(false);
    m_urlCombo.setRenderer(new FlowVariableListCellRenderer());
    m_urlCombo.setMaximumSize(new Dimension(PANEL_WIDTH, buttonHeight));
    m_urlCombo.setMinimumSize(new Dimension(350, buttonHeight));
    m_urlCombo.setPreferredSize(new Dimension(350, buttonHeight));
    fileBox.add(Box.createHorizontalGlue());
    fileBox.add(new JLabel("Flow Variable Name:"));
    fileBox.add(Box.createHorizontalStrut(HORIZ_SPACE));
    fileBox.add(m_urlCombo);
    fileBox.add(Box.createVerticalStrut(50));
    fileBox.add(Box.createHorizontalGlue());
    // the checkbox for preserving the current settings on file change
    Box preserveBox = Box.createHorizontalBox();
    m_preserveSettings = new JCheckBox("Preserve user settings for new location");
    m_preserveSettings.setToolTipText("if not checked, the settings you" + " have set are reset, if a new location is entered");
    m_preserveSettings.setSelected(false);
    m_preserveSettings.setEnabled(true);
    preserveBox.add(Box.createHorizontalGlue());
    preserveBox.add(m_preserveSettings);
    preserveBox.add(Box.createHorizontalGlue());
    panel.add(fileBox);
    panel.add(preserveBox);
    panel.setMaximumSize(new Dimension(PANEL_WIDTH, 70));
    panel.setMinimumSize(new Dimension(PANEL_WIDTH, 70));
    m_urlCombo.addItemListener(this);
    /* install action listeners */
    // set stuff to update preview when file location changes
    m_urlCombo.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(final FocusEvent e) {
            fileLocationChanged();
        }
    });
    return panel;
}
Also used : JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) FlowVariableListCellRenderer(org.knime.core.node.util.FlowVariableListCellRenderer) FocusAdapter(java.awt.event.FocusAdapter) JComboBox(javax.swing.JComboBox) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) JComboBox(javax.swing.JComboBox) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) Dimension(java.awt.Dimension) FocusEvent(java.awt.event.FocusEvent)

Aggregations

FocusAdapter (java.awt.event.FocusAdapter)33 FocusEvent (java.awt.event.FocusEvent)33 JLabel (javax.swing.JLabel)11 JTextField (javax.swing.JTextField)10 Dimension (java.awt.Dimension)8 JPanel (javax.swing.JPanel)7 KeyAdapter (java.awt.event.KeyAdapter)5 KeyEvent (java.awt.event.KeyEvent)5 BoxLayout (javax.swing.BoxLayout)4 JButton (javax.swing.JButton)4 JCheckBox (javax.swing.JCheckBox)4 FlowLayout (java.awt.FlowLayout)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 FocusListener (java.awt.event.FocusListener)3 Box (javax.swing.Box)3 BorderLayout (java.awt.BorderLayout)2 Container (java.awt.Container)2 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2