Java

hata -  
infochiara Messages postés 11 Statut Membre -
Bonjour,
comment afficher une table en java avec un scrolbar
A voir également:

2 réponses

infochiara Messages postés 11 Statut Membre
 
j espere que ce code va t aider

import javax.swing.*;
import javax.swing.table.*;
import java.awt.Dimension;

public void jbInit(){

//table
table = new JTable(modeltable);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));

//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBounds(new Rectangle(1, 27, 680, 600));
//Add the scroll pane to this panel.
add(scrollPane);
}

class MyTableModel extends AbstractTableModel {
public String[] columnNames = { "C1", "C2", "C3l"};

public Object[][] data = {
{ "", "", "" },
{ "", "", "" },
{ "", "", "" },

};

/* public final Object[] longValues = { "Sharon", "Campione",
"None of the above", new Integer(20), Boolean.TRUE };*/

public int getColumnCount() {
return columnNames.length;
}

public int getRowCount() {
return data.length;
}

public String getColumnName(int col) {
return columnNames[col];
}

public Object getValueAt(int row, int col) {
return data[row][col];
}

/*
* JTable uses this method to determine the default renderer/ editor for
* each cell. If we didn't implement this method, then the last column
* would contain text ("true"/"false"), rather than a check box.
*/
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}

/*
* Don't need to implement this method unless your table's editable.
*/
public boolean isCellEditable(int row, int col) {

return true;

}

/*
* Don't need to implement this method unless your table's data can
* change.
*/
public void setValueAt(Object value, int row, int col) {
if (DEBUG) {
System.out.println("Setting value at " + row + "," + col
+ " to " + value + " (an instance of "
+ value.getClass() + ")");
}

data[row][col] = value;
fireTableCellUpdated(row, col);

if (DEBUG) {
System.out.println("New value of data:");
printDebugData();
}
}

private void printDebugData() {
int numRows = getRowCount();
int numCols = getColumnCount();

for (int i = 0; i < numRows; i++) {
System.out.print(" row " + i + ":");
for (int j = 0; j < numCols; j++) {
System.out.print(" " + data[i][j]);
}
System.out.println();
}
System.out.println("--------------------------");
}

}

J ai testé ce code il ,arche consentre toi comment ajouter ce code a votr application
0
infochiara Messages postés 11 Statut Membre
 
j espere que ce code va t aider

import javax.swing.*;
import javax.swing.table.*;
import java.awt.Dimension;

public void jbInit(){

//table
table = new JTable(modeltable);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));

//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBounds(new Rectangle(1, 27, 680, 600));
//Add the scroll pane to this panel.
add(scrollPane);
}

class MyTableModel extends AbstractTableModel {
public String[] columnNames = { "C1", "C2", "C3l"};

public Object[][] data = {
{ "", "", "" },
{ "", "", "" },
{ "", "", "" },

};

/* public final Object[] longValues = { "Sharon", "Campione",
"None of the above", new Integer(20), Boolean.TRUE };*/

public int getColumnCount() {
return columnNames.length;
}

public int getRowCount() {
return data.length;
}

public String getColumnName(int col) {
return columnNames[col];
}

public Object getValueAt(int row, int col) {
return data[row][col];
}

/*
* JTable uses this method to determine the default renderer/ editor for
* each cell. If we didn't implement this method, then the last column
* would contain text ("true"/"false"), rather than a check box.
*/
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}

/*
* Don't need to implement this method unless your table's editable.
*/
public boolean isCellEditable(int row, int col) {

return true;

}

/*
* Don't need to implement this method unless your table's data can
* change.
*/
public void setValueAt(Object value, int row, int col) {
if (DEBUG) {
System.out.println("Setting value at " + row + "," + col
+ " to " + value + " (an instance of "
+ value.getClass() + ")");
}

data[row][col] = value;
fireTableCellUpdated(row, col);

if (DEBUG) {
System.out.println("New value of data:");
printDebugData();
}
}

private void printDebugData() {
int numRows = getRowCount();
int numCols = getColumnCount();

for (int i = 0; i < numRows; i++) {
System.out.print(" row " + i + ":");
for (int j = 0; j < numCols; j++) {
System.out.print(" " + data[i][j]);
}
System.out.println();
}
System.out.println("--------------------------");
}

}

J ai testé ce code il marche consentre toi comment ajouter ce code a votr application
0