概述
我定义了两个全局数组StringrentalBar[]={"车牌号","车型","颜色","使用时间","日租金","卡车载重"};//这是JTable列标题StringreturnDatabase[][]={{"","","","","",""}};构造函数里实...
我定义了两个全局数组
String rentalBar[] = {"车牌号","车型","颜色","使用时间","日租金","卡车载重"};//这是JTable列标题
String returnDatabase[][] = {{"","","","","",""}};
构造函数里实例化了一个JTable将数组添加至,具体就不写了:
rentalTable = new JTable(rentalDatabase,rentalBar);
然后有一个信息录入面板,录入信息种类跟上面renalBar数组中的各个元素一致
当我点击按钮提交信息时,各个种类的信息添加至list
protected void add_ActionPerformed(ActionEvent e){
DatebaseManager dm = new DatebaseManager();
Vehicle car = new Car();
Truck truck = new Truck();
String licensePlateNumber = newCarTitleTF[0].getText();
String arctic = newCarTitleTF[1].getText();
String color = colorChoice.getSelectedItem().toString();
String hoursOfuse = newCarTitleTF[3].getText();
String rentOfday = newCarTitleTF[4].getText();
String truckLoad = newCarTitleTF[4].getText();
if(choiceCarOrTruck()){
car.setLicensePlateNumber(licensePlateNumber);
car.setArctic(arctic);
car.setColor(color);
car.setHoursOfuse(hoursOfuse);
car.setRentOfday(rentOfday);
boolean isAdd = dm.addToDatebase(list, car);
if(isAdd){
JOptionPane.showMessageDialog(this, "添加轿车成功!", null,JOptionPane.INFORMATION_MESSAGE);
System.out.println(list);
}else{
JOptionPane.showMessageDialog(this, "添加轿车失败!", null,JOptionPane.WARNING_MESSAGE);
}
}else{
truck.setLicensePlateNumber(licensePlateNumber);
truck.setArctic(arctic);
truck.setColor(color);
truck.setHoursOfuse(hoursOfuse);
truck.setRentOfday(rentOfday);
truck.setTruckLoad(truckLoad);
boolean isAdd = dm.addToDatebase(list, truck);
if(isAdd){
JOptionPane.showMessageDialog(this, "添加卡车成功!", null,JOptionPane.INFORMATION_MESSAGE);
System.out.println(list);
}else{
JOptionPane.showMessageDialog(this, "添加卡车失败!", null,JOptionPane.WARNING_MESSAGE);
}
}
}
问题来了,我实例化了一个刷新按钮,如何实现点击刷新按钮后就将list中的对象的属性值展示到JTable?
展开
最后
以上就是热情缘分为你收集整理的java table map_JAVA中怎么把list或map里的值动态添加至JTable的全部内容,希望文章能够帮你解决java table map_JAVA中怎么把list或map里的值动态添加至JTable所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复