Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计 » Swing  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 请问如何在JTabbedPane中加入多个JTable?
sy0300014460





发贴: 11
积分: 0
于 2005-03-13 10:47 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
请各位大侠帮帮忙,以下这段代码为何表中的标题总是显示最后一个标题,我希望还是用AbstractTableModel() 这个类来实现显示标题,因为我还得通过它来返回数据库中的信息,然后通过table显示出数据。如果你们有更好的方法,请多多指教,谢谢!!

package student;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
import javax.swing.*;
import java.awt.*;
import javax.swing.table.*;
import com.borland.dbswing.*;
import java.util.*;
public class Untitled1 extends JFrame{
Vector vector;
AbstractTableModel tm;
String head1[]={"id","name","age","class"};
String head2[]={"hello"};
String title[];
JTabbedPane jTabbedPane1 = new JTabbedPane();
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
TableScrollPane tableScrollPane1 = new TableScrollPane();
TableScrollPane tableScrollPane2 = new TableScrollPane();
public Untitled1() {
try {

jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(500,400);
this.setVisible(true);
}

public static void main(String[] args) {
Untitled1 untitled1 = new Untitled1();
}
private void jbInit() throws Exception {

title=head1;
ininTable();
JdbTable jdbTable1 = new JdbTable(tm);
jdbTable1.setAutoResizeMode(jdbTable1.AUTO_RESIZE_ALL_COLUMNS);
this.getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
jTabbedPane1.add(jPanel1, "jPanel1");
jPanel1.add(tableScrollPane1, null);
tableScrollPane1.getViewport().add(jdbTable1, null);

title=head2;
ininTable();
JdbTable jdbTable2 = new JdbTable(tm);
jTabbedPane1.add(jPanel2, "jPanel2");
jPanel2.add(tableScrollPane2, null);
tableScrollPane2.getViewport().add(jdbTable2, null);
}
public void ininTable(){
vector=new Vector();
tm = new AbstractTableModel() {
public int getColumnCount() {
return title.length;
}
public int getRowCount() {
return vector.size();
}
public Object getValueAt(int row, int column) {
if (!vector.isEmpty()) {
return ( (Vector) vector.elementAt(row)).elementAt(column);
}
else {
return null;
}
}
public void setValueAt(Object value, int row, int column) {
}
public String getColumnName(int column) {
return title[column];
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int column) {
return false;
}
};
}
}


image1.bmp (16.58k)


kavinwang edited on 2005-04-16 07:41


学习java的工具(IDE)有什么?

话题树型展开
人气 标题 作者 字数 发贴时间
7287 请问如何在JTabbedPane中加入多个JTable? sy0300014460 2733 2005-03-13 10:47
5333 Re:请问如何在JTabbedPane中加入多个JTable? sy0300014460 47 2005-03-13 10:52
5359 Re:请问如何在JTabbedPane中加入多个JTable? Duncan 1047 2005-03-15 18:18
5287 Re:请问如何在JTabbedPane中加入多个JTable? sy0300014460 61 2005-03-16 18:48
5732 Re:请问如何在JTabbedPane中加入多个JTable? mochow 6 2005-04-15 23:25

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923