codice:
package boundary.gui;
import javax.swing.JPanel;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.UIManager;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import boundary.InserireUnitaImmobiliare;
import boundary.gui.ModelTables.DatiUIModelTable;
import boundary.gui.Renderers.ComboBoxRenderer;
import javax.swing.JButton;
import javax.swing.table.DefaultTableModel;
import java.awt.Insets;
import java.awt.Dimension;
import java.awt.SystemColor;
import java.awt.Color;
import java.util.Vector;
public class GUI_InserireDatiUI extends JDialog {
private static final long serialVersionUID = 1L;
private JPanel pnl_main = null;
private JScrollPane scrpnl_datiUI = null;
private JTable tbl_datiUI = null;
private JButton btn_insNuovoCond = null;
private JButton btn_conferma = null;
private JButton btn_annulla = null;
private InserireUnitaImmobiliare iui = null;
private DefaultTableModel datiUIModel;
/**
* @param owner
*/
public GUI_InserireDatiUI(InserireUnitaImmobiliare iui) {
super();
this.iui = iui;
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
final String windowsTheme = new String("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
try
{
UIManager.setLookAndFeel(windowsTheme);
}
catch(Exception e)
{
System.out.println("Error creating Look And Feel.");
}
this.setSize(733, 300);
this.setTitle("Inserimento Dati Unità Immobiliare");
this.setContentPane(getPnl_main());
this.setVisible(true);
this.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
}
});
}
/**
* This method initializes pnl_main
*
* @return javax.swing.JPanel
*/
private JPanel getPnl_main() {
if (pnl_main == null) {
GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
gridBagConstraints3.gridx = 1;
gridBagConstraints3.anchor = GridBagConstraints.WEST;
gridBagConstraints3.insets = new Insets(0, 50, 10, 0);
gridBagConstraints3.gridy = 2;
GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
gridBagConstraints2.gridx = 0;
gridBagConstraints2.insets = new Insets(0, 280, 10, 0);
gridBagConstraints2.gridy = 2;
GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.gridx = 0;
gridBagConstraints1.gridwidth = 2;
gridBagConstraints1.weightx = 0.0;
gridBagConstraints1.anchor = GridBagConstraints.EAST;
gridBagConstraints1.insets = new Insets(0, 0, 30, 100);
gridBagConstraints1.gridy = 1;
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.gridy = 0;
gridBagConstraints.ipadx = 0;
gridBagConstraints.ipady = 0;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.gridheight = 1;
gridBagConstraints.insets = new Insets(0, 0, 20, 0);
gridBagConstraints.gridx = 0;
pnl_main = new JPanel();
pnl_main.setLayout(new GridBagLayout());
pnl_main.add(getScrpnl_datiUI(), gridBagConstraints);
pnl_main.add(getBtn_insNuovoCond(), gridBagConstraints1);
pnl_main.add(getBtn_conferma(), gridBagConstraints2);
pnl_main.add(getBtn_annulla(), gridBagConstraints3);
}
return pnl_main;
}
/**
* This method initializes scrpnl_datiUI
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getScrpnl_datiUI() {
if (scrpnl_datiUI == null) {
scrpnl_datiUI = new JScrollPane();
scrpnl_datiUI.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrpnl_datiUI.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scrpnl_datiUI.setViewportView(getTbl_datiUI());
}
return scrpnl_datiUI;
}
/**
* This method initializes tbl_datiUI
*
* @return javax.swing.JTable
*/
private JTable getTbl_datiUI() {
if (tbl_datiUI == null) {
//DatiUIModelTable datiUIModel= new DatiUIModelTable();
Object[][] dati = {{new String(), new String(), new String(), new Integer(0), new String(), new String(), new Integer(0)}};
Object[] columnNames = {
"Identificatore",
"Categoria",
"Destinazione",
"Metratura (in mq)",
"Posizione interna",
"Proprietario",
"Quota", };
datiUIModel = new DefaultTableModel(dati, columnNames);
tbl_datiUI = new JTable(datiUIModel);
tbl_datiUI.setRowHeight(20);
tbl_datiUI.setRowSelectionAllowed(false);
tbl_datiUI.setPreferredSize(new Dimension(525, 20));
tbl_datiUI.setIntercellSpacing(new Dimension(1, 1));
tbl_datiUI.setBackground(SystemColor.WHITE);
tbl_datiUI.setForeground(Color.DARK_GRAY);
tbl_datiUI.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
tbl_datiUI.setShowVerticalLines(true);
tbl_datiUI.setSize(new Dimension(710, 20));
tbl_datiUI.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent e) {
/*if(checkId())
{
}*/
}
});
String[] comboBoxItems = {"Genova", "Milano"}; //Array di prova
//String[] Cities;
//String[] Owners;
/*Devo implementare il recupero dei comuni e il recupero dei proprietari.*/
tbl_datiUI.getColumnModel().getColumn(6).setPreferredWidth(20);
tbl_datiUI.getColumnModel().getColumn(2).setCellRenderer(new ComboBoxRenderer(comboBoxItems));
tbl_datiUI.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor( new JComboBox(comboBoxItems)));
tbl_datiUI.getColumnModel().getColumn(5).setCellRenderer(new ComboBoxRenderer(comboBoxItems));
tbl_datiUI.getColumnModel().getColumn(5).setCellEditor(new DefaultCellEditor( new JComboBox(comboBoxItems)));
}
return tbl_datiUI;
}
/**
* This method initializes btn_insNuovoCond
*
* @return javax.swing.JButton
*/
private JButton getBtn_insNuovoCond() {
if (btn_insNuovoCond == null) {
btn_insNuovoCond = new JButton();
btn_insNuovoCond.setText("Inserisci Nuovo Condomino");
}
return btn_insNuovoCond;
}
/**
* This method initializes btn_conferma
*
* @return javax.swing.JButton
*/
private JButton getBtn_conferma() {
if (btn_conferma == null) {
btn_conferma = new JButton();
btn_conferma.setText("Conferma");
btn_conferma.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
Object[] ob = {new String("ciao"), new String(), new String(), new Integer(0), new String(), new String(), new Integer(0)};
datiUIModel.addRow(ob);
//datiUIModel.addRow(ob);
//datiUIModel.fireTableDataChanged();
//fireTableDataChanged();
}
});
}
return btn_conferma;
}
/**
* This method initializes btn_annulla
*
* @return javax.swing.JButton
*/
private JButton getBtn_annulla() {
if (btn_annulla == null) {
btn_annulla = new JButton();
btn_annulla.setText("Annulla");
btn_annulla.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
iui.annulla();
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
});
}
return btn_annulla;
}
} // @jve:decl-index=0:visual-constraint="10,10"