Search in sources :

Example 86 with FocusListener

use of java.awt.event.FocusListener in project java-swing-tips by aterai.

the class MainPanel method makeExpandingTextArea1.

private static Component makeExpandingTextArea1() {
    JPanel p = new JPanel(new BorderLayout());
    JTextArea textArea = new JTextArea(TEXT, 1, 10);
    textArea.setLineWrap(true);
    textArea.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            JTextArea ta = (JTextArea) e.getComponent();
            ta.setRows(3);
            p.revalidate();
        }

        @Override
        public void focusLost(FocusEvent e) {
            JTextArea ta = (JTextArea) e.getComponent();
            ta.setRows(1);
            p.revalidate();
        }
    });
    JScrollPane scroll = new JScrollPane(textArea);
    // scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
    scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    p.add(scroll, BorderLayout.NORTH);
    return p;
}
Also used : FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 87 with FocusListener

use of java.awt.event.FocusListener in project sldeditor by robward-scisys.

the class FieldConfigBoundingBox method createRow.

/**
 * Creates the row.
 *
 * @param label the label
 * @param xPos the x pos
 * @param fieldPanel the field panel
 * @param row the row
 * @return the j text field
 */
private JTextField createRow(String label, int xPos, FieldPanel fieldPanel, int row) {
    JLabel lbl = new JLabel(label);
    lbl.setHorizontalAlignment(SwingConstants.TRAILING);
    lbl.setBounds(xPos, getRowY(row), BasePanel.LABEL_WIDTH, BasePanel.WIDGET_HEIGHT);
    fieldPanel.add(lbl);
    textField = new JTextField();
    textField.setBounds(xPos + BasePanel.WIDGET_X_START, getRowY(row), this.isValueOnly() ? BasePanel.WIDGET_EXTENDED_WIDTH : BasePanel.WIDGET_STANDARD_WIDTH, BasePanel.WIDGET_HEIGHT);
    fieldPanel.add(textField);
    textField.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            originalValue = textField.getText();
        }

        @Override
        public void focusLost(FocusEvent e) {
            valueStored(textField.getText());
        }
    });
    return textField;
}
Also used : JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Aggregations

FocusListener (java.awt.event.FocusListener)87 FocusEvent (java.awt.event.FocusEvent)80 ActionEvent (java.awt.event.ActionEvent)24 ActionListener (java.awt.event.ActionListener)23 JLabel (javax.swing.JLabel)20 JTextField (javax.swing.JTextField)17 Dimension (java.awt.Dimension)16 JPanel (javax.swing.JPanel)16 JButton (javax.swing.JButton)15 KeyEvent (java.awt.event.KeyEvent)12 JComboBox (javax.swing.JComboBox)11 BorderLayout (java.awt.BorderLayout)9 Component (java.awt.Component)9 MouseEvent (java.awt.event.MouseEvent)9 KeyListener (java.awt.event.KeyListener)8 JCheckBox (javax.swing.JCheckBox)8 ChangeListener (javax.swing.event.ChangeListener)8 Color (java.awt.Color)7 GridBagConstraints (java.awt.GridBagConstraints)7 MouseAdapter (java.awt.event.MouseAdapter)7