java,如果我要做一10行10列的表格用JTABLE怎么做啊

数据来源是ACESS表名(STUDENTS)字段随便... 数据来源是ACESS 表名(STUDENTS)
字段随便
展开
 我来答
南京利德盛模温机公司
推荐于2016-09-04 · TA获得超过131个赞
知道小有建树答主
回答量:260
采纳率:0%
帮助的人:142万
展开全部
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
public class JTable_main extends JFrame {
private int rows=3, cols=5;
private Object[] rowData = new Object[cols];

private DefaultTableModel model = new DefaultTableModel();
private JTable table = new JTable(model);

public JTable_main() {
for(int c=0; c < cols; ++c){
model.addColumn("Column " + Integer.toString(c));
}
for(int r=0; r < rows; ++r) {
for(int c=0; c < cols; ++c) {
rowData[c] = "(" + r + "," + c + ")";
}
model.addRow(rowData);
}
getContentPane().add(new JScrollPane(table),BorderLayout.CENTER);
getContentPane().add(new ControlPanel(),BorderLayout.NORTH);
}

public static void main(String args[]) {
GJApp.launch(new JTable_main(),"Using DefaultTableModel",150,150,600,350);
}

class ControlPanel extends JPanel {
private JButton rowButton = new JButton("Add Row"),colButton = new JButton("Add Column");

public ControlPanel() {
add(rowButton);
add(colButton);

rowButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int rowCount = model.getRowCount();
int colCount = model.getColumnCount();

if(colCount > rowData.length) rowData = new Object[colCount];

for(int c=0; c < colCount; ++c) {
rowData[c] = "(" + rowCount + "," + c + ")";
}
model.addRow(rowData);
}
});
colButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int colCount = model.getColumnCount();
model.addColumn("Column " + colCount);

// Bug: the call to sizeColumnsToFit()
// should not be necessary
table.sizeColumnsToFit(-1);
}
});
}
}
}
class GJApp extends WindowAdapter {
static private JPanel statusArea = new JPanel();
static private JLabel status = new JLabel(" ");
static private ResourceBundle resources;

public static void launch(final JFrame f, String title,final int x, final int y, final int w, int h){
launch(f,title,x,y,w,h,null);
}
public static void launch(final JFrame f, String title,
final int x, final int y,
final int w, int h,
String propertiesFilename) {
f.setTitle(title);
f.setBounds(x,y,w,h);
f.setVisible(true);

statusArea.setBorder(BorderFactory.createEtchedBorder());
statusArea.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
statusArea.add(status);
status.setHorizontalAlignment(JLabel.LEFT);

f.setDefaultCloseOperation(
WindowConstants.DISPOSE_ON_CLOSE);

if(propertiesFilename != null) {
resources = ResourceBundle.getBundle(
propertiesFilename, Locale.getDefault());
}

f.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
System.exit(0);
}
});
}
static public JPanel getStatusArea() {
return statusArea;
}
static public void showStatus(String s) {
status.setText(s);
}
static Object getResource(String key) {
if(resources != null) {
return resources.getString(key);
}
return null;
}
}
诚信天下hxl
2009-03-05
知道答主
回答量:18
采纳率:0%
帮助的人:8.9万
展开全部
有3种方法:
Object[][] cellData = {
{"row1-col1", "row1-col2"},
{"row2-col1", "row2-col2"}};

String[] columnNames = {"col1", "col2"};

一、 JTable table = new JTable(cellData, columnNames);
二、int rows = 10;
int cols = 10;
table = new JTable(rows, cols);
三、Vector rowData = new Vector();
for (int i=0; i<cellData.length; i++) {
Vector colData = new Vector(Arrays.asList(cellData[i]));
rowData.add(colData);
}
Vector columnNamesV = new Vector(Arrays.asList(columnNames));

JTable table = new JTable(rowData, columnNamesV);
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
slczai
2009-03-05 · 超过36用户采纳过TA的回答
知道小有建树答主
回答量:212
采纳率:0%
帮助的人:0
展开全部
有对的.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式