1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
public class TreeTableExample0 extends JPanel implements ActionListener
{
static JLabel titre;
static JTextField actuel, nouveau;
static JPanel panneauChamps;
int numligne=-1;
String portlet,value;
Object node;
FileSystemModelprtest model;
final JTreeTable treeTable;
public Dimension getPreferredSize() {
return new Dimension(800, 600);
}
public static void main(String[] args) throws Exception {
titre=new JLabel("voici mon bas de page");
JFrame frame = new JFrame("Test portlet");
//new TreeTableExample0();
TreeTableExample0 test=new TreeTableExample0();
//test.setSize(new Dimension(500,500));
frame.getContentPane().add(panneauChamps,"North");
frame.getContentPane().add(test,"Center");
frame.getContentPane().add(titre,"South");
frame.getContentPane().add(test);
frame.setSize(test.getPreferredSize());
frame.pack();
frame.show();
}
public TreeTableExample0() throws Exception {
panneauChamps=new JPanel(new GridLayout(2,1));
actuel=new JTextField();
nouveau=new JTextField();
nouveau.setActionCommand("ligne suivante");
nouveau.addActionListener(this);
panneauChamps.add(actuel);
panneauChamps.add(nouveau);
//String path = System.getProperty("user.home");
//InputSource path=new InputSource("les 2 ensembles.pte");
String path="les 2 ensembles.pte";
//String path="config.xml";
node=null;
model =new FileSystemModelprtest(path);
treeTable = new JTreeTable(model);
treeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
treeTable.setSize(700,500);
treeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) return;
int t=treeTable.getSelectedRow();
if( !nouveau.getText().equals("") && !(numligne==-1) && node!=null){
System.out.println("suis la");
model.setValueAt(nouveau.getText(),node,2);}
if(t>=0){
actuel.setText((String)treeTable.getValueAt(t,1));
nouveau.setText((String)treeTable.getValueAt(t,2));
node=treeTable.getValueAt(t,0);
nouveau.requestFocus();
numligne=t;
portlet="";
}
}});
//treeTable.setSize(getPreferredSize());
JScrollPane scrollpane=new JScrollPane(treeTable);
scrollpane.setSize(700,500);
add(scrollpane);
}
/* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
String commande;
commande = e.getActionCommand();
if (commande.equals("ligne suivante")){
if(treeTable.getSelectedRow()<treeTable.getRowCount()-1)
treeTable.setRowSelectionInterval(treeTable.getSelectedRow()+1, treeTable.getSelectedRow()+1);
else if(treeTable.getSelectedRow()>0)
treeTable.setRowSelectionInterval(treeTable.getSelectedRow()-1, treeTable.getSelectedRow()-1);
}
}
} |
Partager