Bijour tt le monde.
J'ai un ti souci Java. PLus spécialement JTable.
En fait J'arrive )as à afficher les titre de mes collonnes.
Ci joint le code pour les amateurs (c long mais y a rien de complexe).
/*-------------------------------- *
/*
* OTCApplet.java
*
* Created on 12 février 2004, 14:56
*/
/**
*
* @author developpement
*/
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.applet.*;
import java.net.*;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
public class OTCApplet extends JApplet {
/** Jtable*/
JTable stock_first_line;
JTable stock_second_line;
JTable entete_otcex_interests;
JTable liste_interests;
JTable entete_otcex_trades;
JTable liste_trade;
/* Les panneaux */
JPanel StockPanel;
JPanel ListPanel;
/* Pour la gestion des données dans la Jtable de l'action 1ere ligne*/
class Stock1dataModel extends AbstractTableModel {
final String[] columnNames = {"Nom","Go", "lastprice","change","avgstockvol","avgoptionvol","avgopen", "mosttradedexp","mosttradedstk","time"};
Object [][] data = {{"Nom","Go", "Last Price","Change %","avgstockvol","avgoptionvol","avgopen", "mosttradedexp","mosttradedstk","time"}};
public int getColumnCount() { return 10; }
public int getRowCount() { return 1;}
public Object getValueAt(int row,int col) {return data[row][col];}
public void setValueAt(Object aValue,int row, int col) { data[row][col] = aValue; }
};
/* Pour la gestion des données dans la Jtable de l'action 1ere ligne*/
class Stock2dataModel extends AbstractTableModel {
final String[] columnNames = {"ISIN","Market", "Last Price","Change %","avgstockvol","avgoptionvol","avgopen", "mosttradedexp","mosttradedstk","time"};
Object [][] data = {{"ISIN","Market", "Last Price","Change %","avgstockvol","avgoptionvol","avgopen", "mosttradedexp","mosttradedstk","time"}};
public int getColumnCount() { return 10; }
public int getRowCount() { return 1;}
public Object getValueAt(int row,int col) {return data[row][col];}
public void setValueAt(Object aValue,int row, int col) { data[row][col] = aValue; }
};
class InterestDataModel extends AbstractTableModel {
final String[] columnNames = {"I#","Prod","Exp1","Exp2","Exp3","Exp4","Strk1","Strk2","Strk3","Strk4","Strategy","Réf","Listed Bid", "Bid","OTC Vol","OTC vol","OTC Ask","Listed Ask","Delta","Vega","Theta","Volume Listed","time"};
Object [][] data = {{"I#","Prod","Exp1","Exp2","Exp3","Exp4","Strk1","Strk2","Strk3","Strk4","Strategy","Réf","Listed Bid","Bid","OTC Vol","OTC vol","OTC Ask","Listed Ask","Delta","Vega","Theta","Volume Listed","time"},
{"I#","Prod","Exp1","Exp2","Exp3","Exp4","Strk1","Strk2","Strk3","Strk4","Strategy","Réf","Listed Bid","Bid","OTC Vol","OTC vol","OTC Ask","Listed Ask","Delta","Vega","Theta","Volume Listed","time"},
{"I#","Prod","Exp1","Exp2","Exp3","Exp4","Strk1","Strk2","Strk3","Strk4","Strategy","Réf","Listed Bid","Bid","OTC Vol","OTC vol","OTC Ask","Listed Ask","Delta","Vega","Theta","Volume Listed","time"},
{"I#","Prod","Exp1","Exp2","Exp3","Exp4","Strk1","Strk2","Strk3","Strk4","Strategy","Réf","Listed Bid","Bid","OTC Vol","OTC vol","OTC Ask","Listed Ask","Delta","Vega","Theta","Volume Listed","time"},
{"I#","Prod","Exp1","Exp2","Exp3","Exp4","Strk1","Strk2","Strk3","Strk4","Strategy","Réf","Listed Bid","Bid","OTC Vol","OTC vol","OTC Ask","Listed Ask","Delta","Vega","Theta","Volume Listed","time"}};
public int getColumnCount() { return 23; }
public int getRowCount() { return 5;}
public Object getValueAt(int row,int col) {return data[row][col];}
public void setValueAt(Object aValue,int row, int col) { data[row][col] = aValue; }
};
/* class qui permet de personnaliser l'intérieurs des cellules (couleur, font images, ...) */
class CustomRenderer extends DefaultTableCellRenderer {
String txt;
Color color;
CustomRenderer(String s,Color c){
txt = s;
color = c;
}
public void SetColor(Color c){ color = c; }
public void setTxt(String s){ txt = s; }
public void setValue(Object value) {
setBackground(color);
setText(txt);
setHorizontalAlignment(JLabel.CENTER);
}
};
Stock1dataModel stock1dataModel;
Stock2dataModel stock2dataModel;
InterestDataModel interestDataModel;
/* fin des variables */
public void init() {
/* init de s l'applet */
getContentPane().setLayout(new GridLayout(3,1));
getContentPane().setSize(1000,600);
getContentPane().setName("OTCex" );
/* init des JPanel et du JScrollPane*/
StockPanel = new JPanel();
StockPanel.setBackground(Color.white);
ListPanel = new JPanel();
ListPanel.setBackground(Color.red);
/* init des Jtable */
stock1dataModel = new Stock1dataModel();
stock_first_line = new JTable(stock1dataModel);
stock2dataModel = new Stock2dataModel();
stock_second_line = new JTable(stock2dataModel);
interestDataModel = new InterestDataModel();
liste_interests = new JTable(interestDataModel);
/* Init des Largeurs de colonnes du tableau 1ere ligne de param de l'action */
stock_first_line.setEnabled(false);
TableColumn column = stock_first_line.getColumnModel().getColumn(0);
column.setPreferredWidth(180);
column = stock_first_line.getColumnModel().getColumn(1);
column.setPreferredWidth(20);
column = stock_first_line.getColumnModel().getColumn(2);
column.setPreferredWidth(50);
column = stock_first_line.getColumnModel().getColumn(3);
column.setPreferredWidth(50);
column = stock_first_line.getColumnModel().getColumn(4);
column.setPreferredWidth(125);
column = stock_first_line.getColumnModel().getColumn(5);
column.setPreferredWidth(125);
column = stock_first_line.getColumnModel().getColumn(6);
column.setPreferredWidth(125);
column = stock_first_line.getColumnModel().getColumn(7);
column.setPreferredWidth(125);
column = stock_first_line.getColumnModel().getColumn(8);
column.setPreferredWidth(150);
column = stock_first_line.getColumnModel().getColumn(9);
column.setPreferredWidth(50);
/* Init des Largeurs de colonnes du tableau 2eme ligne de param de l'action */
stock_second_line.setEnabled(false);
column = stock_second_line.getColumnModel().getColumn(0);
column.setPreferredWidth(120);
column = stock_second_line.getColumnModel().getColumn(1);
column.setPreferredWidth(80);
column = stock_second_line.getColumnModel().getColumn(2);
column.setPreferredWidth(50);
column = stock_second_line.getColumnModel().getColumn(3);
column.setPreferredWidth(50);
column = stock_second_line.getColumnModel().getColumn(4);
column.setPreferredWidth(125);
column = stock_second_line.getColumnModel().getColumn(5);
column.setPreferredWidth(125);
column = stock_second_line.getColumnModel().getColumn(6);
column.setPreferredWidth(125);
column = stock_second_line.getColumnModel().getColumn(7);
column.setPreferredWidth(125);
column = stock_second_line.getColumnModel().getColumn(8);
column.setPreferredWidth(150);
column = stock_second_line.getColumnModel().getColumn(9);
column.setPreferredWidth(50);
/* init de l'entete otcex interest */
entete_otcex_interests = new JTable(1, 2);
entete_otcex_interests.setEnabled(false);
entete_otcex_interests.setValueAt("OTCex Interest", 0, 0);
entete_otcex_interests.setValueAt("Time", 0, 1);
column = entete_otcex_interests.getColumnModel().getColumn(0);
column.setPreferredWidth(950);
column = entete_otcex_interests.getColumnModel().getColumn(1);
column.setPreferredWidth(50);
/* init de la liste des interest */
//liste_interests.setEnabled(false);
liste_interests.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
liste_interests.setCellSelectionEnabled(false);
liste_interests.getTableHeader().setVisible(true);
column = liste_interests.getColumnModel().getColumn(0);
column.setPreferredWidth(50);
column = liste_interests.getColumnModel().getColumn(1);
column.setPreferredWidth(50);
column = liste_interests.getColumnModel().getColumn(2);
column.setPreferredWidth(50);
column = liste_interests.getColumnModel().getColumn(3);
column.setPreferredWidth(50);
column = liste_interests.getColumnModel().getColumn(4);
column.setPreferredWidth(50);
column = liste_interests.getColumnModel().getColumn(5);
column.setPreferredWidth(50);
column = liste_interests.getColumnModel().getColumn(6);
column.setPreferredWidth(50);
column = liste_interests.getColumnModel().getColumn(7);
column.setPreferredWidth(50);
column = liste_interests.getColumnModel().getColumn(8);
column.setPreferredWidth(50);
column = liste_interests.getColumnModel().getColumn(9);
column.setPreferredWidth(50);
column = liste_interests.getColumnModel().getColumn(10);
column.setPreferredWidth(20);
column = liste_interests.getColumnModel().getColumn(11);
column.setPreferredWidth(50);
column = liste_interests.getColumnModel().getColumn(12);
column.setPreferredWidth(20);
column = liste_interests.getColumnModel().getColumn(13);
column.setPreferredWidth(50);
column = liste_interests.getColumnModel().getColumn(14);
column.setPreferredWidth(50);
column = liste_interests.getColumnModel().getColumn(15);
column.setPreferredWidth(50);
column = liste_interests.getColumnModel().getColumn(16);
column.setPreferredWidth(50);
column = liste_interests.getColumnModel().getColumn(17);
column.setPreferredWidth(50);
column = liste_interests.getColumnModel().getColumn(18);
column.setPreferredWidth(50);
column = liste_interests.getColumnModel().getColumn(19);
column.setPreferredWidth(20);
column = liste_interests.getColumnModel().getColumn(20);
column.setPreferredWidth(30);
column = liste_interests.getColumnModel().getColumn(21);
column.setPreferredWidth(30);
column = liste_interests.getColumnModel().getColumn(22);
column.setPreferredWidth(30);
/* init de l'entete otcex Trades */
entete_otcex_trades = new JTable(1, 2);
entete_otcex_trades.setEnabled(false);
entete_otcex_trades.setValueAt("OTCex Trades", 0, 0);
entete_otcex_trades.setValueAt("Time", 0, 1);
column = entete_otcex_trades.getColumnModel().getColumn(0);
column.setPreferredWidth(950);
column = entete_otcex_trades.getColumnModel().getColumn(1);
column.setPreferredWidth(50);
liste_trade = new JTable(1, 10);
/* Ajout des JTable ds le panel */
StockPanel.add(stock_first_line);
StockPanel.add(stock_second_line);
ListPanel.add(entete_otcex_interests);
ListPanel.add(liste_interests);
ListPanel.add(entete_otcex_trades);
//ListPanel.add(liste_trade);
/* ajout des composantrs dans l'applet */
getContentPane().add(StockPanel);
getContentPane().add(ListPanel);
}
}