Je rencontre un petit problème (je suppose) d'affichage du panneau JTable. Je classe contient tableau d'objets avec:ne peut pas afficher JTable
public class Item
{
String itemDesc = "";
float price = 0;
private itemType enmItemType;
Object[][] data = {{itemDesc, enmItemType , new Float(price)}};
.
.
.
.
}
est ici la classe table contient les JTable:
class Table extends JFrame
{
// Instance attributes used in this example
private JPanel topPanel;
private JTable table;
private JScrollPane scrollPane;
private JButton update_Button;
// Constructor of main frame
public Table()
{
// Set the frame characteristics
setTitle("Add new item");
setSize(300, 200);
setBackground(Color.gray);
// Create a panel to hold all other components
topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
getContentPane().add(topPanel);
// Create columns names
String columnNames[] = {"Item Description", "Item Type", "Item Price"};
// Create some data
Object dataValues[][] ;
Item itm = new Item();
dataValues = itm.data;
// Create a new table instance
table = new JTable(dataValues, columnNames);
////////////////////////////
JComboBox itemTypeCombobox = new JComboBox();
TableColumn column1 = table.getColumnModel().getColumn(1);
column1.setCellEditor(new DefaultCellEditor(itemTypeCombobox));
////////////////////////////
// Add the table to a scrolling pane
scrollPane = new JScrollPane(table);
topPanel.add(scrollPane, BorderLayout.CENTER);
JButton button = new JButton("Add Item");
topPanel.add(button, BorderLayout.SOUTH);
}
}
Le programme principal est:
public static void main(String[] args)
{
Menu m = new Menu();
m.chooseMenu();
// Create an instance of the test application
Table mainFrame = new Table();
mainFrame.setVisible(true);
}
Je n'ai reçu aucune erreur/warning, mais je ne vois toujours pas de table. Quelqu'un peut-il me dire ce qui cause le problème?
Merci.
@Edan: Veuillez essayer d'améliorer la mise en forme de votre code. Utilisez 'Code Sample (Ctrl + K)' au lieu de 'Blockquote (Ctrl + q)'. –
je vais la prochaine fois ... – firestruq
Je le veux cette fois que j'ai des erreurs de compilation .. Vous pouvez toujours modifier votre code .. – bragboy