Salve, avrei un problema.....
sto giusto toccando java per ingannare il tempo. Quando eseguo il programma, la finestra la disegna correttamente... ma appena clicco nella JTextArea, e scrivo un carattere, la textarea si ingrandice fino a occupare l'intera finestra come per magia. Sapete aiutarmi?
codice:
import java.awt.Color;
import javax.swing.*;
public class Main {
private JFrame frame;
private JTextArea text;
private JButton pulsante;
private JButton p2;
private JScrollPane panel;
public Main(){
crea();
disegna();
}
public void crea(){
frame = new JFrame("Finestra");
pulsante = new JButton("OK");
p2 = new JButton("Chiudi");
panel = new JScrollPane();
text = new JTextArea();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void disegna(){
frame.setSize(800,800);
frame.setBackground(Color.darkGray);
frame.setVisible(true);
pulsante.setSize(60, 20);
pulsante.setVisible(true);
pulsante.setLocation(10, 310);
p2.setSize(60, 20);
p2.setVisible(true);
p2.setLocation(100, 310);
text.setVisible(true);
text.setSize(300, 300);
//panel.setViewportView(text);
frame.add(pulsante);
frame.add(p2);
frame.add(text);
}
/** * @param args the command line arguments */
public static void main(String[] args) {
new Main();
}
}
ho notato che nel metodo disegna(), si ingrandisce a tutta finestra il componente che aggiungo al frame per ultimo, in questo caso è 'text', ma se peer ultimo aggiungo 'p2', si ingrandirà appunto 'p2'.
Aiuti?