Is it possible to write a class and hava a another class add that to a panel?
ceyesuma -4 Posting Pro
Hello,
Can someone point out why my table is not showing up?
I show that the data is showing up in rs and the tablePanel is in place and my thisUserLbl is (not a table) but is displaying.
but no table visible.
Thanks.
output:
in the inner abstact table class:
colCount: 15
headers: ADMIN_UID
headers: ADMIN_PASSWORD
headers: ADMIN_LNAME
headers: ADMIN_MNAME
headers: ADMIN_FNAME
headers: ADMIN_GENDER
headers: ADMIN_AGE
headers: ADMIN_START_DATE
headers: ADMIN_END_DATE
headers: ADMIN_ADDRESS
headers: ADMIN_STATE
headers: ADMIN_ZIP
headers: ADMIN_AREA_CODE
headers: ADMIN_PHONE
headers: ADMIN_PAY_RATE
records in: ag
records in: a
records in: null
records in: null
records in: Garth
records in: null
records in: null
records in: null
records in: null
records in: null
records in: null
records in: null
records in: null
records in: null
records in: null
uid used for personalData: ag
in getConnection of DerbyDAOFactory
driver tableName from xml: org.apache.derby.jdbc.EmbeddedDriver
in StudentDAO.JAVA and in connect of the ConnectDerbyDAO
returns isConnected: true
AdminPanel: uid to use: ag
AdminPanel: imported from ViewUtils.getUid: ag
uid used for personalData: ag
in getConnection of DerbyDAOFactory
driver tableName from xml: org.apache.derby.jdbc.EmbeddedDriver
in StudentDAO.JAVA and in connect of the ConnectDerbyDAO
returns isConnected: true
in the inner abstact table class:
colCount: 15
headers: ADMIN_UID
headers: ADMIN_PASSWORD
headers: ADMIN_LNAME
headers: ADMIN_MNAME
headers: ADMIN_FNAME
headers: ADMIN_GENDER
headers: ADMIN_AGE
headers: ADMIN_START_DATE
headers: ADMIN_END_DATE
headers: ADMIN_ADDRESS
headers: ADMIN_STATE
headers: ADMIN_ZIP
headers: ADMIN_AREA_CODE
headers: ADMIN_PHONE
headers: ADMIN_PAY_RATE
records in: ag
records in: a
records in: null
records in: null
records in: Garth
records in: null
records in: null
records in: null
records in: null
records in: null
records in: null
records in: null
records in: null
records in: null
records in: null
uid used for personalData: ag
public TableModel qtm;
public ResultSetMetaData rsmd;
public ResultSet rs;
/** Creates new form AdminPanel */
public AdminPanel() throws FileNotFoundException, IOException, SQLException {
initComponents();
setThisUser(ViewUtils.getThisUser());
setProfile(ViewUtils.isAdmin());
System.out.println("AdminPanel: imported from ViewUtils.getUid: " + thisUser);
personalData(thisUser);
panelData(thisUser);
}
//////////////////////////////////////////////////////////////////
////////////////// set up model ////////////////////////
/////////////////////////////////////////////////////////////////
public void personalData(String thisUser) throws FileNotFoundException, IOException, SQLException {
ConnectAdminDAO cad = new ConnectAdminDAO();
ResultSet rs = cad.personalData(thisUser);//send param to return the rs from query
ResultSetMetaData rsmd = rs.getMetaData();
//pct.printColTypes(rsmd);
qtm = new TableModel();
qtm.setQuery(rs, rsmd);
JTable table = new JTable((TableModel) qtm);
JScrollPane scrollpane = new JScrollPane(table);
scrollpane.setVisible(true);
scrollpane.setAlignmentX(TOP_ALIGNMENT);
scrollpane.setAlignmentY(TOP_ALIGNMENT);
tablePanel.add(scrollpane);
tablePanel.setBorder(BorderFactory.createLoweredBevelBorder());
add(tablePanel);
rs.close();
}
public void panelData(String thisUser) throws FileNotFoundException, IOException, SQLException {
cad = new ConnectAdminDAO();
rs = cad.panelData(thisUser);//send param to return the rs from query
rsmd = rs.getMetaData();
System.out.println("AdminPanel: uid to use: " + thisUser);
while (rs.next()) {
setThisUser(rs.getString(1));
setlName(rs.getString(3));
setmName(rs.getString(4));
setfName(rs.getString(5));
setGender(rs.getString(6));
setStartDate(rs.getDate(7));
setEndDate(rs.getDate(8));
setAge(rs.getInt(9));
setAddress(rs.getString(10));
setState(rs.getString(11));
setZip(rs.getInt(12));
setAreaCode(rs.getInt(13));
setPhone(rs.getInt(14));
setPayRate(rs.getDouble(15));
}
rs.close();
thisUserLbl.setText(fName);
}
//////////////////////////////////////////////////////////////////
////////////////// set up model ////////////////////////
/////////////////////////////////////////////////////////////////
[b]
public class TableModel extends AbstractTableModel {
[/b]
public Vector cache; // will hold String[] objects . . .
public int colCount;
public String[] headers;
public ResultSet rs;
public ResultSetMetaData rsmd;
public TableModel() {
}
public void setQuery(ResultSet rs, ResultSetMetaData rsmd) throws FileNotFoundException, IOException, SQLException {
System.out.println("in the inner abstact table class: ");
cache = new Vector();
try {
// Execute the query and store the result set and its metadata
colCount = rsmd.getColumnCount();
System.out.println("colCount: " + colCount);
// Now we must rebuild the headers array with the new column names
headers = new String[colCount];
for (int h = 1; h <= colCount; h++) {
headers[h - 1] = rsmd.getColumnName(h);
System.out.println("headers: " + rsmd.getColumnName(h));
}
while (rs.next()) {
String[] record = new String[colCount];
for (int i = 0; i < colCount; i++) {
record[i] = rs.getString(i + 1);
System.out.println("records in: " + rs.getString(i + 1));
}
cache.addElement(record);
}
fireTableChanged(null); // notify everyone that we have a new table.
} catch (Exception e) {
cache = new Vector(); // blank it out and keep going.
e.printStackTrace();
}
}
@Override
public String getColumnName(int i) {
return headers[i];
}
public int getColumnCount() {
return colCount;
}
public int getRowCount() {
return cache.size();
}
public Object getValueAt(int row, int col) {
return ((String[]) cache.elementAt(row))[col];
}
public ResultSet getRs() {
return rs;
}
public void setRs(ResultSet rs) {
this.rs = rs;
}
}
..............
ceyesuma -4 Posting Pro
hello this is the same code but I changed the way the inner class is called and cleaned up the output some. Still no table is rendered
Thanks
output
In ok_cancel: [C@18a49e0
LoginInfo profile: admin_
CREATED NEW INSTANCE OF ConnectAdminDAO
LoginInfo profile: admin_
LoginInfo user: ag
in getConnection of DerbyDAOFactory
driver tableName from xml: org.apache.derby.jdbc.EmbeddedDriver
in StudentDAO.JAVA and in connect of the ConnectDerbyDAO
returns isConnected: true
adminUserName: SELECT admin_uid FROM admin WHERE admin_uid=?
adminPassword: SELECT admin_password FROM admin WHERE admin_uid=?
selectAdmin:
SELECT
admin_uid,
admin_password,
admin_lname,
admin_mname,
admin_fname,
admin_gender,
admin_age,
admin_start_date,
admin_end_date,
admin_address,
admin_state,
admin_zip,
admin_area_code,
admin_phone,
admin_pay_rate
FROM admin
WHERE admin_uid=?
CONECTION IS GOOD FOR A TEST
query test: selectAllAdmin
number of columns: 15
, ADMIN_UID, ADMIN_PASSWORD, ADMIN_LNAME, ADMIN_MNAME, ADMIN_FNAME, ADMIN_GENDER, ADMIN_AGE, ADMIN_START_DATE, ADMIN_END_DATE, ADMIN_ADDRESS, ADMIN_STATE, ADMIN_ZIP, ADMIN_AREA_CODE, ADMIN_PHONE, ADMIN_PAY_RATE
, ag, a, null, null, Garth, null, null, null, null, null, null, null, null, null, null
, aw, a, null, null, Wayne, null, null, null, null, null, null, null, null, null, null
adminUserName: SELECT admin_uid FROM admin WHERE admin_uid=?
adminPassword: SELECT admin_password FROM admin WHERE admin_uid=?
selectAdmin:
SELECT
admin_uid,
admin_password,
admin_lname,
admin_mname,
admin_fname,
admin_gender,
admin_age,
admin_start_date,
admin_end_date,
admin_address,
admin_state,
admin_zip,
admin_area_code,
admin_phone,
admin_pay_rate
FROM admin
WHERE admin_uid=?
CONECTION IS GOOD FOR A TEST
query test: selectAllAdmin
number of columns: 15
, ADMIN_UID, ADMIN_PASSWORD, ADMIN_LNAME, ADMIN_MNAME, ADMIN_FNAME, ADMIN_GENDER, ADMIN_AGE, ADMIN_START_DATE, ADMIN_END_DATE, ADMIN_ADDRESS, ADMIN_STATE, ADMIN_ZIP, ADMIN_AREA_CODE, ADMIN_PHONE, ADMIN_PAY_RATE
, ag, a, null, null, Garth, null, null, null, null, null, null, null, null, null, null
, aw, a, null, null, Wayne, null, null, null, null, null, null, null, null, null, null
in getConnection of DerbyDAOFactory
driver tableName from xml: org.apache.derby.jdbc.EmbeddedDriver
in StudentDAO.JAVA and in connect of the ConnectDerbyDAO
returns isConnected: true
returned: profile
so,count and name: admin_guideTab.total admin_guideTabLabels
start obj() type= guide
uid used for personalData: ag
in getConnection of DerbyDAOFactory
driver tableName from xml: org.apache.derby.jdbc.EmbeddedDriver
in StudentDAO.JAVA and in connect of the ConnectDerbyDAO
returns isConnected: true
uid used for personalData: ag
in getConnection of DerbyDAOFactory
driver tableName from xml: org.apache.derby.jdbc.EmbeddedDriver
in StudentDAO.JAVA and in connect of the ConnectDerbyDAO
returns isConnected: true
in getConnection of DerbyDAOFactory
driver tableName from xml: org.apache.derby.jdbc.EmbeddedDriver
in StudentDAO.JAVA and in connect of the ConnectDerbyDAO
returns isConnected: true
headers: ADMIN_UID
headers: ADMIN_PASSWORD
headers: ADMIN_LNAME
headers: ADMIN_MNAME
headers: ADMIN_FNAME
headers: ADMIN_GENDER
headers: ADMIN_AGE
headers: ADMIN_START_DATE
headers: ADMIN_END_DATE
headers: ADMIN_ADDRESS
headers: ADMIN_STATE
headers: ADMIN_ZIP
headers: ADMIN_AREA_CODE
headers: ADMIN_PHONE
headers: ADMIN_PAY_RATE
records in: ag
records in: a
records in: null
records in: null
records in: Garth
records in: null
records in: null
records in: null
records in: null
records in: null
records in: null
records in: null
records in: null
records in: null
records in: null
innerclass: setQuery(): 15 Columns and 1 records
package view.content.panels.guide;
import java.awt.Dimension;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Date;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import model.dao.ConnectAdminDAO;
import view.ViewUtils;
/**
*
* @author depot
*/
public class AdminPanel extends javax.swing.JPanel {
public ConnectAdminDAO cad;
private String thisUser;
private boolean profile;
public boolean student;
public boolean instructor;
public boolean admin;
public boolean payee;
public String fName;
public String lName;
public String mName;
public String gender;
public Date startDate;
public Date endDate;
public int age;
public String address;
public String state;
public int zip;
public int areaCode;
public int phone;
public String payeeUid;
public String lessonLocation;
public Double payRate;
public int bookNum;
public String stuUid;
public int rate;
public TableModel tm;
public ResultSetMetaData rsmd;
public ResultSet rs;
public String[] record;
public int recordCount;
/** Creates new form AdminPanel */
public AdminPanel() throws FileNotFoundException, IOException, SQLException {
initComponents();
setThisUser(ViewUtils.getThisUser());
setProfile(ViewUtils.isAdmin());
personalDataTable(thisUser);
panelData(thisUser);
}
//////////////////////////////////////////////////////////////////
////////////////// set up model ////////////////////////
/////////////////////////////////////////////////////////////////
public void personalDataTable(String thisUser) throws FileNotFoundException, IOException, SQLException {
cad = new ConnectAdminDAO();
rs = cad.personalDataTable(thisUser);//send param to return the rs from query
rsmd = rs.getMetaData();
//pct.printColTypes(rsmd);
tm = new TableModel();
tm.setQuery(rs, rsmd);
JTable table = new JTable(tm);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);
JScrollPane scrollpane = new JScrollPane(table);
scrollpane.setVisible(true);
tablePanel.add(scrollpane);
tablePanel.setBorder(BorderFactory.createLoweredBevelBorder());
add(tablePanel);
rs.close();
}
public void panelData(String thisUser) throws FileNotFoundException, IOException, SQLException {
cad = new ConnectAdminDAO();
rs = cad.panelData(thisUser);//send param to return the rs from query
rsmd = rs.getMetaData();
while (rs.next()) {
setThisUser(rs.getString(1));
setlName(rs.getString(3));
setmName(rs.getString(4));
setfName(rs.getString(5));
setGender(rs.getString(6));
setStartDate(rs.getDate(7));
setEndDate(rs.getDate(8));
setAge(rs.getInt(9));
setAddress(rs.getString(10));
setState(rs.getString(11));
setZip(rs.getInt(12));
setAreaCode(rs.getInt(13));
setPhone(rs.getInt(14));
setPayRate(rs.getDouble(15));
}
rs.close();
thisUserLbl.setText(fName);
}
//////////////////////////////////////////////////////////////////
////////////////// set up model ////////////////////////
/////////////////////////////////////////////////////////////////
public class TableModel extends AbstractTableModel {
public Vector cache; // will hold String[] objects . . .
public int colCount;
public String[] headers;
public ResultSet rs;
public ResultSetMetaData rsmd;
public void setQuery(ResultSet rs, ResultSetMetaData rsmd) throws FileNotFoundException, IOException, SQLException {
recordCount=0;
cache = new Vector();
try {
// Execute the query and store the result set and its metadata
colCount = rsmd.getColumnCount();
// Now we must rebuild the headers array with the new column names
headers = new String[colCount];
for (int h = 1; h <= colCount; h++) {
headers[h - 1] = rsmd.getColumnName(h);
System.out.println("headers: " + rsmd.getColumnName(h));
}
while (rs.next()) {
record = new String[colCount];
for (int i = 0; i < colCount; i++) {
record[i] = rs.getString(i + 1);
System.out.println("records in: " + rs.getString(i + 1));
}
recordCount++;
cache.addElement(record);
}
fireTableChanged(null); // notify everyone that we have a new table.
System.out.println("innerclass: setQuery(): "+
rsmd.getColumnCount()+" Columns and "+recordCount+" records");
} catch (Exception e) {
cache = new Vector(); // blank it out and keep going.
e.printStackTrace();
}
}
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.