62,628
社区成员
发帖
与我相关
我的任务
分享import javax.swing.*;
import javax.swing.table.*;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.util.Vector;
public class TableTest extends JFrame{
public TableTest(Vector columnName,Vector tableValue){
super();
final TableTest1 panel = new TableTest1(columnName,tableValue);
this.setBounds(300,200,300,200);
this.add(panel,BorderLayout.CENTER);
this.setVisible(true);
}
class TableTest1 extends JPanel{
private Vector<String> columnName;
private Vector<Vector<Object>> tableValue;
private int fixed = 1;
public TableTest1(Vector columnName, Vector tableValue){
super();
this.setBounds(300,200,300,200);
this.columnName = columnName;
this.tableValue = tableValue;
Fixed fixedTableModel = new Fixed();
JTable fixedTable = new JTable(fixedTableModel);
Fixed floatingTableModel = new Fixed();
JTable floatingTable = new JTable(floatingTableModel);
floatingTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
JScrollPane sp = new JScrollPane();
sp.setCorner(JScrollPane.UPPER_LEFT_CORNER, fixedTable.getTableHeader());
JViewport viewport = new JViewport();
viewport.setView(fixedTable);
viewport.setPreferredSize(fixedTable.getPreferredSize());
sp.setRowHeader(viewport);
sp.setViewportView(floatingTable);
this.add(sp,BorderLayout.CENTER);
this.setVisible(true);
}
public class Fixed extends AbstractTableModel{
public int getColumnCount(){
return fixed;
}
public int getRowCount(){
return tableValue.size();
}
public Object getValueAt(int row, int column){
return tableValue.get(row).get(column);
}
public String getColumnName(int column){
return columnName.get(column);
}
}
public class Floating extends AbstractTableModel{
public int getColumnCount(){
return columnName.size() - fixed;
}
public int getRowCount(){
return tableValue.size();
}
public Object getValueAt(int row, int column){
return tableValue.get(row).get(column + fixed);
}
public String getColumnName(int column){
return columnName.get(column + fixed);
}
}
}
public static void main(String[] args){
Vector columnName = new Vector();
columnName.add("日期");
for(int i = 0 ; i < 21 ; i++ ){
columnName.add("商品"+i);
}
Vector tableValue = new Vector();
for(int row = 1 ; row < 31 ; row++ ){
Vector rowV = new Vector();
rowV.add(row);
for(int col = 0 ; col < 20 ; col++ ){
rowV.add((int)Math.random()*1000);
}
tableValue.add(rowV);
}
new TableTest(columnName,tableValue);
}
}

import javax.swing.*;
import javax.swing.table.*;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.util.Vector;
public class TableTest extends JFrame{
public TableTest(Vector columnName,Vector tableValue){
super();
final TableTest1 panel = new TableTest1(columnName,tableValue);
this.setBounds(300,200,300,200);
this.add(panel,BorderLayout.CENTER);
this.setVisible(true);
}
class TableTest1 extends JPanel{
private Vector<String> columnName;
private Vector<Vector<Object>> tableValue;
private int fixed = 1;
public TableTest1(Vector columnName, Vector tableValue){
super();
this.setBounds(300,200,300,200);
this.columnName = columnName;
this.tableValue = tableValue;
Fixed fixedTableModel = new Fixed();
JTable fixedTable = new JTable(fixedTableModel);
Floating floatingTableModel = new Floating(); //mark
JTable floatingTable = new JTable(floatingTableModel);
floatingTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
JScrollPane sp = new JScrollPane();
sp.setCorner(JScrollPane.UPPER_LEFT_CORNER, fixedTable.getTableHeader());
JViewport viewport = new JViewport();
viewport.setView(fixedTable);
viewport.setPreferredSize(fixedTable.getPreferredSize());
sp.setRowHeader(viewport);
sp.setViewportView(floatingTable);
this.add(sp,BorderLayout.CENTER);
this.setVisible(true);
}
public class Fixed extends AbstractTableModel{
public int getColumnCount(){
return fixed;
}
public int getRowCount(){
return tableValue.size();
}
public Object getValueAt(int row, int column){
return tableValue.get(row).get(column);
}
public String getColumnName(int column){
return columnName.get(column);
}
}
public class Floating extends AbstractTableModel{
public int getColumnCount(){
return columnName.size() - fixed;
}
public int getRowCount(){
return tableValue.size();
}
public Object getValueAt(int row, int column){
return tableValue.get(row).get(column + fixed);
}
public String getColumnName(int column){
return columnName.get(column + fixed);
}
}
}
public static void main(String[] args){
Vector columnName = new Vector();
columnName.add("日期");
for(int i = 0 ; i < 21 ; i++ ){
columnName.add("商品"+i);
}
Vector tableValue = new Vector();
for(int row = 1 ; row < 31 ; row++ ){
Vector rowV = new Vector();
rowV.add(row);
for(int col = 0 ; col < 20 ; col++ ){
rowV.add((int)Math.random()*1000);
}
tableValue.add(rowV);
}
new TableTest(columnName,tableValue);
}
}import java.awt.BorderLayout;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JViewport;
import javax.swing.table.AbstractTableModel;
public class TableTest extends JFrame {
public TableTest(Vector columnName, Vector tableValue) {
super();
final TableTest1 panel = new TableTest1(columnName, tableValue);
this.setBounds(300, 200, 300, 200);
this.add(panel, BorderLayout.CENTER);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
class TableTest1 extends JScrollPane {
private Vector<String> columnName;
private Vector<Vector<Object>> tableValue;
private int fixed = 1;
public TableTest1(Vector columnName, Vector tableValue) {
super();
this.columnName = columnName;
this.tableValue = tableValue;
Fixed fixedTableModel = new Fixed();
JTable fixedTable = new JTable(fixedTableModel);
Floating floatingTableModel = new Floating(); // mark
JTable floatingTable = new JTable(floatingTableModel);
floatingTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
this.setCorner(JScrollPane.UPPER_LEFT_CORNER, fixedTable
.getTableHeader());
JViewport viewport = new JViewport();
viewport.setView(fixedTable);
viewport.setPreferredSize(fixedTable.getPreferredSize());
this.setRowHeader(viewport);
this.setViewportView(floatingTable);
this.setVisible(true);
}
public class Fixed extends AbstractTableModel {
public int getColumnCount() {
return fixed;
}
public int getRowCount() {
return tableValue.size();
}
public Object getValueAt(int row, int column) {
return tableValue.get(row).get(column);
}
public String getColumnName(int column) {
return columnName.get(column);
}
}
public class Floating extends AbstractTableModel {
public int getColumnCount() {
return columnName.size() - fixed;
}
public int getRowCount() {
return tableValue.size();
}
public Object getValueAt(int row, int column) {
return tableValue.get(row).get(column + fixed);
}
public String getColumnName(int column) {
return columnName.get(column + fixed);
}
}
}
public static void main(String[] args) {
Vector columnName = new Vector();
columnName.add("日期");
for (int i = 0; i < 21; i++) {
columnName.add("商品" + i);
}
Vector tableValue = new Vector();
for (int row = 1; row < 31; row++) {
Vector rowV = new Vector();
rowV.add(row);
for (int col = 0; col < 21; col++) {
rowV.add((int) Math.random() * 1000);
}
tableValue.add(rowV);
}
new TableTest(columnName, tableValue);
}
}