Salve a tutti!
Ho un problema con il GridBagLayout...
Dovrei visualizzare in un frame 4 textfield con 4 label (prompt..)
Mi riesco tutto...soltato che le textfield me le fa troppo piccole..Aumento la gridwidth ma niente ecco tutto il programma..
-----------------------------------------------------
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
public class Agende extends Frame {
////////////////////////////////////////////////////////////////////
/////////////////// CLASSE: AGENDE ///////////////////////
////////////////////////////////////////////////////////////////////
TextField tNome, tCognome, tTelefono, tNote;
public static void main(String a[]) {
Agende ist = new Agende();
}
Agende() {
// ASCOLTATORI
MyActionListener al = new MyActionListener(); // AZIONI...
MyItemListener il = new MyItemListener(); // LISTA...
MyKeyListener kl = new MyKeyListener(); // TASTIERA...
MyWindowListener wl = new MyWindowListener(); // FINESTRA...
addWindowListener(wl);
// FINE ascoltatori
// MENU'
MenuBar barraMenu = new MenuBar();
setMenuBar (barraMenu);
Menu mFile = new Menu ("File");
mFile.add (new MenuItem("Esci")).addActionListener(al);
//
// GRAIDBAGLAYOUT
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setFont(new Font("Verdana", Font.PLAIN, 14));
// CREO i pannelli
Panel PannelloCentro = new Panel();
PannelloCentro.setLayout(gridbag);
c.fill = GridBagConstraints.CENTER;
creaTextField(PannelloCentro, "Nome", tNome, gridbag, c, 1, 1, 5, 1);
creaTextField(PannelloCentro, "Cognome", tCognome, gridbag, c, 1, 8, 5, 1);
creaTextField(PannelloCentro, "Telefono", tTelefono, gridbag, c, 1, 16, 5, 1);
creaTextField(PannelloCentro, "Note", tNote, gridbag, c, 1, 24, 5, 1);
add(PannelloCentro, "Center"); // AGGIUNGO IL PANNELLO
setTitle("Agenda: 1.0");
setVisible(true);
setBounds(30,10, 300, 300);
} // FINE costruttore
//// FUNZIONE creaTextField
public void creaTextField(Panel p, String Etichetta, TextField t, GridBagLayout gridbag, GridBagConstraints c, int x, int y, int altezza, int larghezza) {
c.gridx = x;
c.gridy = y;
c.gridwidth = larghezza;
c.gridheight = altezza;
Label l = new Label(Etichetta);
gridbag.setConstraints(l, c);
p.add(l);
// Dimensioni della TextField
c.gridx = x + 2;
c.gridy = y;
c.gridwidth = larghezza + 2;
c.gridheight = altezza;
t = new TextField();
gridbag.setConstraints(t, c);
p.add(t);
}
////
//// FUNZIONE vediStato
public void vediStato() {
}
////
///////// CLASSE MyActionListener /////////////
class MyActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Esci")) {
dispose();
System.exit(0);
}
}
}
///////////
///////// CLASSE MyWindowListener /////////////
class MyWindowListener extends WindowAdapter {
public void windowClosed(WindowEvent e) {
System.exit(0);
}
public void windowClosing(WindowEvent e) {
e.getWindow().dispose();
}
}
///////////
///////// CLASSE MyItemListener /////////////
class MyItemListener implements ItemListener {
public void itemStateChanged(ItemEvent ve) {
vediStato();
}
}
///////////
///////// CLASSE MyKeyListener /////////////
class MyKeyListener extends KeyAdapter {
public void keyTyped(KeyEvent e) {
}
}
///////////
////////////////////////////////////////////////////////////////////
/////////////// FINE CLASSE: AGENDE ///////////////////////
////////////////////////////////////////////////////////////////////
} // FINE CLASSE MADRE
-----------------------------------------------------
GRAZIE A TUTTI