Au secours au secours java pb compilation
Fermé
pepsi
-
12 mai 2004 à 16:36
silfaxu Messages postés 102 Date d'inscription jeudi 18 décembre 2003 Statut Contributeur Dernière intervention 6 février 2008 - 13 mai 2004 à 09:16
silfaxu Messages postés 102 Date d'inscription jeudi 18 décembre 2003 Statut Contributeur Dernière intervention 6 février 2008 - 13 mai 2004 à 09:16
A voir également:
- Au secours au secours java pb compilation
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel football - Télécharger - Jeux vidéo
- Java apk - Télécharger - Langages
- Java décompiler - Télécharger - Langages
- Java runtime - Télécharger - Langages
3 réponses
slt,
Avec quel outils vous développez ?
votre pb de compil vient surement du fait que vous implémentez l'interface ActionListener,
et vous n'avez pas inclus les méthodes qui vont avec !
ajoutez donc la méthode :
public void actionPerformed(ActionEvent e)
{
// A compléter
}
et votre pb de compil devrai disparaitre !
Avec quel outils vous développez ?
votre pb de compil vient surement du fait que vous implémentez l'interface ActionListener,
et vous n'avez pas inclus les méthodes qui vont avec !
ajoutez donc la méthode :
public void actionPerformed(ActionEvent e)
{
// A compléter
}
et votre pb de compil devrai disparaitre !
Bonsoir,
que dire de plus
compartimenter bien vos border lay, Jpanel et autre
c'est plus facile a deboger ensuite
servées vous de l'heritage
super class , class cela sera utile car vous n'aurait pas bseoin de réecrire plusieur fois vos methodes
et si vous vouler que les bouton vous renvoi quelque chose
implementer setActionCommand
et declaré vos bouton a l'exterieur du constructeur
rest à votre disposition @+christian
exemple d'appli sur sdk 1.3.09 et ous quel versi?
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Color;
public class Fenetre7 extends JFrame {
private JTable tableView;
private TableModel dataModel;
public Fenetre7(){
super("Etat des Stocks et Materiels");
setSize(800,600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container Pane=getContentPane();
FlowLayout flow=new FlowLayout(FlowLayout.CENTER);
setVisible(true);
//Panneau global de fond
JPanel fond = new JPanel(new BorderLayout());
fond.setBackground(Color.orange);
getContentPane().add(fond);
setVisible(true);
//les menus :
MenuBar mbar = new MenuBar( );
Menu meprinc1 = new Menu("Fichier");
Menu meprinc2 = new Menu("Edition");
Menu meprinc3 = new Menu("Affichage");
Menu meprinc4 = new Menu("Insertion");
Menu meprinc5 = new Menu("Format");
Menu meprinc6 = new Menu("Aide");
MenuItem item1 = new MenuItem("Enregistrer");
MenuItem item2 = new MenuItem("Enregistrer sous");
MenuItem item3 = new MenuItem("Imprimer");
MenuItem item4 = new MenuItem("Apercu avant impression");
MenuItem item5 = new MenuItem("Mise en page");
MenuItem item6 = new MenuItem("Envoyer");
MenuItem item7 = new MenuItem("Quitter");
setMenuBar(mbar);
meprinc1.add(item1);
meprinc1.add(item2);
meprinc1.add(item3);
meprinc1.add(item4);
meprinc1.add(item5);
meprinc1.add(item6);
meprinc1.add(item7);
mbar.add(meprinc1);
mbar.add(meprinc2);
mbar.add(meprinc3);
mbar.add(meprinc4);
mbar.add(meprinc5);
mbar.add(meprinc6);
JPanel row1= new JPanel();
GridLayout grid=new GridLayout(5,5);
row1.setBackground(Color.orange);
fond.add(row1, BorderLayout.CENTER);
row1.setLayout(grid);
setContentPane(row1);
setVisible(true);
//definition de la premiere ligne
JPanel row2=new JPanel();
JLabel NumberFromFileLabel =new JLabel("Responsable des Stocks:",JLabel.CENTER);
row2.add(NumberFromFileLabel);
JTextField responsabledesStocks=new JTextField(15);
FlowLayout layout1 = new FlowLayout(FlowLayout.CENTER,10,10);
Container Pane1 = getContentPane();
Pane1.setLayout(layout1);
row2.setLayout(layout1);
row2.add(responsabledesStocks);
Pane1.add (NumberFromFileLabel);
Pane1.add(responsabledesStocks);
setContentPane(Pane1);
//definition de la troisieme ligne
JPanel row4=new JPanel();
JLabel ResponsibleFromBusinessLabel=new JLabel("Etat en Date du:");
row4.add(ResponsibleFromBusinessLabel);
JTextField EtatenDatedu=new JTextField(12);
FlowLayout flow2=new FlowLayout(FlowLayout.CENTER);
Container pane3= getContentPane();
pane3.setLayout(flow2);
row4.add(EtatenDatedu);
pane3.add(ResponsibleFromBusinessLabel);
pane3.add(EtatenDatedu);
setContentPane(pane3);
setVisible(true);
JPanel row5=new JPanel();
JLabel ResposibleFromBusinessLabel=new JLabel("Fait tout les:");
row5.add(ResposibleFromBusinessLabel);
JTextField Faittoutles=new JTextField(12);
FlowLayout flow3=new FlowLayout(FlowLayout.CENTER);
Container pane4= getContentPane();
pane4.setLayout(flow2);
row5.add(Faittoutles);
pane4.add(ResposibleFromBusinessLabel);
pane4.add(Faittoutles);
setContentPane(pane4);
setVisible(true);
JPanel row6=new JPanel();
JLabel piecevlplLabel=new JLabel("PIECES VL PL:");
row6.add (piecevlplLabel);
fond.setBackground(Color.orange);
JTextArea piecevlpl=new JTextArea(4,11);
piecevlpl.setLineWrap(true);
piecevlpl.setWrapStyleWord(true);
JScrollPane scroll=new JScrollPane(piecevlpl,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Container Pane5=getContentPane();
row6.add(scroll);
Pane5.add(row6);
setContentPane(Pane5);
setVisible(true);
JPanel row7=new JPanel();
JLabel pieceenginsLabel=new JLabel("PIECES ENGINS:");
row7.add (pieceenginsLabel);
JTextArea pieceengins=new JTextArea(4,11);
pieceengins.setLineWrap(true);
pieceengins.setWrapStyleWord(true);
JScrollPane scroll1=new JScrollPane(pieceengins,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Container Pane6=getContentPane();
row7.add(scroll1);
Pane6.add(row7);
setContentPane(Pane6);
setVisible(true);
JPanel row8=new JPanel();
JLabel piecemachineLabel=new JLabel("PIECES MACHINES:");
row8.add (piecemachineLabel);
JTextArea piecemachine=new JTextArea(4,11);
piecemachine.setLineWrap(true);
piecemachine.setWrapStyleWord(true);
JScrollPane scroll2=new JScrollPane(piecemachine,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Container Pane7=getContentPane();
row8.add(scroll2);
Pane7.add(row8);
setContentPane(Pane7);
setVisible(true);
JPanel row9=new JPanel();
JLabel consommablesLabel=new JLabel("CONSOMMABLE:");
row9.add (consommablesLabel);
JTextArea consommables=new JTextArea(4,14);
consommables.setLineWrap(true);
consommables.setWrapStyleWord(true);
JScrollPane scroll3=new JScrollPane(consommables,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Container Pane8=getContentPane();
row9.add(scroll3);
Pane8.add(row9);
setContentPane(Pane8);
setVisible(true);
JPanel row10=new JPanel();
JLabel produitchimiqueLabel=new JLabel("PRODUIT CHIMIQUE:");
row10.add (produitchimiqueLabel);
JTextArea produitchimique=new JTextArea(4,14);
produitchimique.setLineWrap(true);
produitchimique.setWrapStyleWord(true);
JScrollPane scroll4=new JScrollPane(produitchimique,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Container Pane9=getContentPane();
row10.add(scroll4);
Pane9.add(row10);
setContentPane(Pane9);
setVisible(true);
JPanel row11=new JPanel();
JLabel autresLabel=new JLabel("AUTRES:");
row11.add (autresLabel);
JTextArea autres=new JTextArea(4,12);
autres.setLineWrap(true);
autres.setWrapStyleWord(true);
JScrollPane scroll5=new JScrollPane(autres,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Container Pane10=getContentPane();
row11.add(scroll5);
Pane10.add(row11);
setContentPane(Pane10);
setVisible(true);
// Take the dummy data from SwingSet.
final String[] names = {"Energie", "Ltrs Kg","Marques", "Habituel Color",
"Transporteurs","Interlocuteur","A fournir tout les ","Approvisionne le", "Respect des delais oui non"};
final Object[][] data = {
{"Essence", "","", "blanc","","","", new Integer(1), new Boolean(true)},
{"Gasoil", "","", "jaunatre","","","", new Integer(1), new Boolean(false)},
{"Fuel", "","", "rouge","","","", new Integer(1), new Boolean(false)},
{"Huile Hydr", "","", "marron","","","", new Integer(1), new Boolean(true)},
{"Huile Mot", "","", "marron","","","", new Integer(1), new Boolean(false)},
{"Huile Ch", "","", "vert","","","", new Integer(1), new Boolean(false)},
{"Liquide refr", "","", "bleu","","","", new Integer(1), new Boolean(false)},
{"Liquide fr", "","", "blanc","","","", new Integer(1), new Boolean(false)},
{"", "","", "aures","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "","", " ","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "", "","","","","", new Integer(1), new Boolean(false)}
};
// Create a model of the data.
TableModel dataModel = new AbstractTableModel() {
// These methods always need to be implemented.
public int getColumnCount() { return names.length; }
public int getRowCount() { return data.length;}
public Object getValueAt(int row, int col) {return data[row][col];}
// The default implementations of these methods in
// AbstractTableModel would work, but we can refine them.
public String getColumnName(int column) {return names[column];}
public Class getColumnClass(int c) {return getValueAt(0, c).getClass();}
public boolean isCellEditable(int row, int col) {return true;}
public void setValueAt(Object aValue, int row, int column) {
System.out.println("Setting value to: " + aValue);
data[row][column] = aValue;
}
};
// Create the table
JTable tableView = new JTable(dataModel);
// Turn off auto-resizing so that we can set column sizes programmatically.
// In this mode, all columns will get their preferred widths, as set blow.
tableView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
// Create a combo box to show that you can use one in a table.
JComboBox comboBox = new JComboBox();
comboBox.addItem("blanc");
comboBox.addItem("Jaunatre");
comboBox.addItem("rouge");
comboBox.addItem("vert");
comboBox.addItem("marron");
comboBox.addItem("bleu");
comboBox.addItem("autres");
TableColumn colorColumn = tableView.getColumn("Habituel Color");
// Use the combo box as the editor in the "Habituel Color" column.
colorColumn.setCellEditor(new DefaultCellEditor(comboBox));
// Set a pink background and tooltip for the Color column renderer.
DefaultTableCellRenderer colorColumnRenderer = new DefaultTableCellRenderer();
colorColumnRenderer.setBackground(Color.pink);
colorColumnRenderer.setToolTipText("Click for combo box");
colorColumn.setCellRenderer(colorColumnRenderer);
// Set a tooltip for the header of the colors column.
TableCellRenderer headerRenderer = colorColumn.getHeaderRenderer();
if (headerRenderer instanceof DefaultTableCellRenderer)
((DefaultTableCellRenderer)headerRenderer).setToolTipText("Hi Mom!");
// Set the width of the "Respect des delais oui non" column.
TableColumn respectdesdelaisouinonColumn = tableView.getColumn("Respect des delais oui non");
respectdesdelaisouinonColumn.setPreferredWidth(100);
// Show the values in the "Approvisionne le" column in different colors.
TableColumn numbersColumn = tableView.getColumn("Approvisionne le");
DefaultTableCellRenderer numberColumnRenderer = new DefaultTableCellRenderer() {
public void setValue(Object value) {
int cellValue = (value instanceof Number) ? ((Number)value).intValue() : 0;
setForeground((cellValue > 30) ? Color.black : Color.red);
setText((value == null) ? "" : value.toString());
}
};
numberColumnRenderer.setHorizontalAlignment(JLabel.RIGHT);
numbersColumn.setCellRenderer(numberColumnRenderer);
numbersColumn.setPreferredWidth(110);
// Finish setting up the table.
JScrollPane scrollpane = new JScrollPane(tableView);
scrollpane.setBorder(new BevelBorder(BevelBorder.LOWERED));
scrollpane.setPreferredSize(new Dimension(800, 600));
getContentPane().add(scrollpane);
pack();
setVisible(true);
}
public static void main(String[]arguments){
Fenetre7 fen7=new Fenetre7();
}
}
que dire de plus
compartimenter bien vos border lay, Jpanel et autre
c'est plus facile a deboger ensuite
servées vous de l'heritage
super class , class cela sera utile car vous n'aurait pas bseoin de réecrire plusieur fois vos methodes
et si vous vouler que les bouton vous renvoi quelque chose
implementer setActionCommand
et declaré vos bouton a l'exterieur du constructeur
rest à votre disposition @+christian
exemple d'appli sur sdk 1.3.09 et ous quel versi?
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Color;
public class Fenetre7 extends JFrame {
private JTable tableView;
private TableModel dataModel;
public Fenetre7(){
super("Etat des Stocks et Materiels");
setSize(800,600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container Pane=getContentPane();
FlowLayout flow=new FlowLayout(FlowLayout.CENTER);
setVisible(true);
//Panneau global de fond
JPanel fond = new JPanel(new BorderLayout());
fond.setBackground(Color.orange);
getContentPane().add(fond);
setVisible(true);
//les menus :
MenuBar mbar = new MenuBar( );
Menu meprinc1 = new Menu("Fichier");
Menu meprinc2 = new Menu("Edition");
Menu meprinc3 = new Menu("Affichage");
Menu meprinc4 = new Menu("Insertion");
Menu meprinc5 = new Menu("Format");
Menu meprinc6 = new Menu("Aide");
MenuItem item1 = new MenuItem("Enregistrer");
MenuItem item2 = new MenuItem("Enregistrer sous");
MenuItem item3 = new MenuItem("Imprimer");
MenuItem item4 = new MenuItem("Apercu avant impression");
MenuItem item5 = new MenuItem("Mise en page");
MenuItem item6 = new MenuItem("Envoyer");
MenuItem item7 = new MenuItem("Quitter");
setMenuBar(mbar);
meprinc1.add(item1);
meprinc1.add(item2);
meprinc1.add(item3);
meprinc1.add(item4);
meprinc1.add(item5);
meprinc1.add(item6);
meprinc1.add(item7);
mbar.add(meprinc1);
mbar.add(meprinc2);
mbar.add(meprinc3);
mbar.add(meprinc4);
mbar.add(meprinc5);
mbar.add(meprinc6);
JPanel row1= new JPanel();
GridLayout grid=new GridLayout(5,5);
row1.setBackground(Color.orange);
fond.add(row1, BorderLayout.CENTER);
row1.setLayout(grid);
setContentPane(row1);
setVisible(true);
//definition de la premiere ligne
JPanel row2=new JPanel();
JLabel NumberFromFileLabel =new JLabel("Responsable des Stocks:",JLabel.CENTER);
row2.add(NumberFromFileLabel);
JTextField responsabledesStocks=new JTextField(15);
FlowLayout layout1 = new FlowLayout(FlowLayout.CENTER,10,10);
Container Pane1 = getContentPane();
Pane1.setLayout(layout1);
row2.setLayout(layout1);
row2.add(responsabledesStocks);
Pane1.add (NumberFromFileLabel);
Pane1.add(responsabledesStocks);
setContentPane(Pane1);
//definition de la troisieme ligne
JPanel row4=new JPanel();
JLabel ResponsibleFromBusinessLabel=new JLabel("Etat en Date du:");
row4.add(ResponsibleFromBusinessLabel);
JTextField EtatenDatedu=new JTextField(12);
FlowLayout flow2=new FlowLayout(FlowLayout.CENTER);
Container pane3= getContentPane();
pane3.setLayout(flow2);
row4.add(EtatenDatedu);
pane3.add(ResponsibleFromBusinessLabel);
pane3.add(EtatenDatedu);
setContentPane(pane3);
setVisible(true);
JPanel row5=new JPanel();
JLabel ResposibleFromBusinessLabel=new JLabel("Fait tout les:");
row5.add(ResposibleFromBusinessLabel);
JTextField Faittoutles=new JTextField(12);
FlowLayout flow3=new FlowLayout(FlowLayout.CENTER);
Container pane4= getContentPane();
pane4.setLayout(flow2);
row5.add(Faittoutles);
pane4.add(ResposibleFromBusinessLabel);
pane4.add(Faittoutles);
setContentPane(pane4);
setVisible(true);
JPanel row6=new JPanel();
JLabel piecevlplLabel=new JLabel("PIECES VL PL:");
row6.add (piecevlplLabel);
fond.setBackground(Color.orange);
JTextArea piecevlpl=new JTextArea(4,11);
piecevlpl.setLineWrap(true);
piecevlpl.setWrapStyleWord(true);
JScrollPane scroll=new JScrollPane(piecevlpl,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Container Pane5=getContentPane();
row6.add(scroll);
Pane5.add(row6);
setContentPane(Pane5);
setVisible(true);
JPanel row7=new JPanel();
JLabel pieceenginsLabel=new JLabel("PIECES ENGINS:");
row7.add (pieceenginsLabel);
JTextArea pieceengins=new JTextArea(4,11);
pieceengins.setLineWrap(true);
pieceengins.setWrapStyleWord(true);
JScrollPane scroll1=new JScrollPane(pieceengins,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Container Pane6=getContentPane();
row7.add(scroll1);
Pane6.add(row7);
setContentPane(Pane6);
setVisible(true);
JPanel row8=new JPanel();
JLabel piecemachineLabel=new JLabel("PIECES MACHINES:");
row8.add (piecemachineLabel);
JTextArea piecemachine=new JTextArea(4,11);
piecemachine.setLineWrap(true);
piecemachine.setWrapStyleWord(true);
JScrollPane scroll2=new JScrollPane(piecemachine,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Container Pane7=getContentPane();
row8.add(scroll2);
Pane7.add(row8);
setContentPane(Pane7);
setVisible(true);
JPanel row9=new JPanel();
JLabel consommablesLabel=new JLabel("CONSOMMABLE:");
row9.add (consommablesLabel);
JTextArea consommables=new JTextArea(4,14);
consommables.setLineWrap(true);
consommables.setWrapStyleWord(true);
JScrollPane scroll3=new JScrollPane(consommables,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Container Pane8=getContentPane();
row9.add(scroll3);
Pane8.add(row9);
setContentPane(Pane8);
setVisible(true);
JPanel row10=new JPanel();
JLabel produitchimiqueLabel=new JLabel("PRODUIT CHIMIQUE:");
row10.add (produitchimiqueLabel);
JTextArea produitchimique=new JTextArea(4,14);
produitchimique.setLineWrap(true);
produitchimique.setWrapStyleWord(true);
JScrollPane scroll4=new JScrollPane(produitchimique,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Container Pane9=getContentPane();
row10.add(scroll4);
Pane9.add(row10);
setContentPane(Pane9);
setVisible(true);
JPanel row11=new JPanel();
JLabel autresLabel=new JLabel("AUTRES:");
row11.add (autresLabel);
JTextArea autres=new JTextArea(4,12);
autres.setLineWrap(true);
autres.setWrapStyleWord(true);
JScrollPane scroll5=new JScrollPane(autres,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Container Pane10=getContentPane();
row11.add(scroll5);
Pane10.add(row11);
setContentPane(Pane10);
setVisible(true);
// Take the dummy data from SwingSet.
final String[] names = {"Energie", "Ltrs Kg","Marques", "Habituel Color",
"Transporteurs","Interlocuteur","A fournir tout les ","Approvisionne le", "Respect des delais oui non"};
final Object[][] data = {
{"Essence", "","", "blanc","","","", new Integer(1), new Boolean(true)},
{"Gasoil", "","", "jaunatre","","","", new Integer(1), new Boolean(false)},
{"Fuel", "","", "rouge","","","", new Integer(1), new Boolean(false)},
{"Huile Hydr", "","", "marron","","","", new Integer(1), new Boolean(true)},
{"Huile Mot", "","", "marron","","","", new Integer(1), new Boolean(false)},
{"Huile Ch", "","", "vert","","","", new Integer(1), new Boolean(false)},
{"Liquide refr", "","", "bleu","","","", new Integer(1), new Boolean(false)},
{"Liquide fr", "","", "blanc","","","", new Integer(1), new Boolean(false)},
{"", "","", "aures","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "","", " ","","","", new Integer(1), new Boolean(false)},
{"", "","", "","","","", new Integer(1), new Boolean(false)},
{"", "", "","","","","", new Integer(1), new Boolean(false)}
};
// Create a model of the data.
TableModel dataModel = new AbstractTableModel() {
// These methods always need to be implemented.
public int getColumnCount() { return names.length; }
public int getRowCount() { return data.length;}
public Object getValueAt(int row, int col) {return data[row][col];}
// The default implementations of these methods in
// AbstractTableModel would work, but we can refine them.
public String getColumnName(int column) {return names[column];}
public Class getColumnClass(int c) {return getValueAt(0, c).getClass();}
public boolean isCellEditable(int row, int col) {return true;}
public void setValueAt(Object aValue, int row, int column) {
System.out.println("Setting value to: " + aValue);
data[row][column] = aValue;
}
};
// Create the table
JTable tableView = new JTable(dataModel);
// Turn off auto-resizing so that we can set column sizes programmatically.
// In this mode, all columns will get their preferred widths, as set blow.
tableView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
// Create a combo box to show that you can use one in a table.
JComboBox comboBox = new JComboBox();
comboBox.addItem("blanc");
comboBox.addItem("Jaunatre");
comboBox.addItem("rouge");
comboBox.addItem("vert");
comboBox.addItem("marron");
comboBox.addItem("bleu");
comboBox.addItem("autres");
TableColumn colorColumn = tableView.getColumn("Habituel Color");
// Use the combo box as the editor in the "Habituel Color" column.
colorColumn.setCellEditor(new DefaultCellEditor(comboBox));
// Set a pink background and tooltip for the Color column renderer.
DefaultTableCellRenderer colorColumnRenderer = new DefaultTableCellRenderer();
colorColumnRenderer.setBackground(Color.pink);
colorColumnRenderer.setToolTipText("Click for combo box");
colorColumn.setCellRenderer(colorColumnRenderer);
// Set a tooltip for the header of the colors column.
TableCellRenderer headerRenderer = colorColumn.getHeaderRenderer();
if (headerRenderer instanceof DefaultTableCellRenderer)
((DefaultTableCellRenderer)headerRenderer).setToolTipText("Hi Mom!");
// Set the width of the "Respect des delais oui non" column.
TableColumn respectdesdelaisouinonColumn = tableView.getColumn("Respect des delais oui non");
respectdesdelaisouinonColumn.setPreferredWidth(100);
// Show the values in the "Approvisionne le" column in different colors.
TableColumn numbersColumn = tableView.getColumn("Approvisionne le");
DefaultTableCellRenderer numberColumnRenderer = new DefaultTableCellRenderer() {
public void setValue(Object value) {
int cellValue = (value instanceof Number) ? ((Number)value).intValue() : 0;
setForeground((cellValue > 30) ? Color.black : Color.red);
setText((value == null) ? "" : value.toString());
}
};
numberColumnRenderer.setHorizontalAlignment(JLabel.RIGHT);
numbersColumn.setCellRenderer(numberColumnRenderer);
numbersColumn.setPreferredWidth(110);
// Finish setting up the table.
JScrollPane scrollpane = new JScrollPane(tableView);
scrollpane.setBorder(new BevelBorder(BevelBorder.LOWERED));
scrollpane.setPreferredSize(new Dimension(800, 600));
getContentPane().add(scrollpane);
pack();
setVisible(true);
}
public static void main(String[]arguments){
Fenetre7 fen7=new Fenetre7();
}
}
silfaxu
Messages postés
102
Date d'inscription
jeudi 18 décembre 2003
Statut
Contributeur
Dernière intervention
6 février 2008
11
13 mai 2004 à 09:16
13 mai 2004 à 09:16
Salut,
Peux-tu donner l'erreur que tu as à la compilation ?
sfx
Peux-tu donner l'erreur que tu as à la compilation ?
sfx