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;
}
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;
}
Aggregations