0
"Analysis", "Date"및 "Price"열 이름이있는 JTable을 만들고 싶습니다. 분석 및 가격 값은 데이터베이스의 데이터베이스에서 복구되며 날짜는 현재 날짜의 값을 가져옵니다.JTable의 값을 동적으로 설정하십시오.
나는 다음과 같은 클래스 MyModel 만든:
package com.pack.classes;
import java.util.LinkedList;
import javax.swing.table.AbstractTableModel;
import com.pack.beans.MyElement;
@SuppressWarnings("serial")
public class MyModel extends AbstractTableModel {
public static final String[] columnNames = {"Analyse", "Date d'analyse","Prix"};
private final LinkedList<MyElement> list;
public MyModel() {
list = new LinkedList<MyElement>();
}
public void addElement(MyElement e) {
// Adds the element in the last position in the list
list.add(e);
fireTableRowsInserted(list.size()-1, list.size()-1);
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public int getRowCount() {
return list.size();
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
switch(columnIndex) {
case 0: return list.get(rowIndex).getAnalysis();
case 1: return list.get(rowIndex).getDate();
case 2: return list.get(rowIndex).getPrice();
}
return null;
}
}
을 그리고 난 다음과 같은 콩 MyElement를 만들 : 여기
package com.pack.beans;
import java.util.Date;
public class MyElement {
String analysis;
Date date;
Double price;
public String getAnalysis() {
return analysis;
}
public void setAnalysis(String analysis) {
this.analysis = analysis;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
}
이 클래스를 사용하는 내 코드의 조각을 :
String sql = "Select name,number_b from analysis_tab where name ='" + idclicked + "'";
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date date = new Date();
System.out.println(dateFormat.format(date));
PreparedStatement preparestate = database.con.prepareStatement(sql);
ResultSet rs = preparestate.executeQuery();
MyModel mymodel = new MyModel();
String [] value = mymodel.columnNames;
MyElement e = new MyElement();
//e.setAnalysis(name);
e.setDate(date);
//e.setPrice("number_b");
결과로 난 .I이 때문에 제 몰라 3 coloumn "A"와 "B"및 "C"를 테이블을 구하는 ese 이름은 온다 !!! "Analyze", "Date d' analyze", "Prix"등의 열 이름을 표의 머리글에 넣을 수있는 방법을 알려주시겠습니까?
[JTable을위한 튜토리얼] (http://docs.oracle.com/javase/tutorial/uiswing/components/table.html)을 읽어보십시오. – alex2410
무엇을할까요? JTable을 만드시겠습니까? [oracle tutorial] (http://docs.oracle.com/javase/tutorial/uiswing/components/table.html)을 검색하십시오. – jhamon
그냥 MyColumnNames 메서드를 MyModel 클래스에 추가하면됩니다. :) – Sarra