Domanda

How could I set 2 textfields as one viewport and set each textfield to expand as more text is typed in, rather than adding a scroll bar to each textfield.

I find it hard to describe it with words so I have uploaded a sketch.

enter image description here

È stato utile?

Soluzione

You could do something like this, everytime you type something in, it gets bigger:

field.addKeyListener(this);

And in your KeyListener implementation this:

@Override
public void keyReleased(KeyEvent arg0) {
    field.setSize(field.getWidth() + 10, field.getHeight());
    repaint();
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top