Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,155,234 members, 7,825,904 topics. Date: Monday, 13 May 2024 at 05:49 AM

Update Jtable At Runtime - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Update Jtable At Runtime (1426 Views)

Windows Runtime Errors / Conpaas - An Open-source Runtime Environment For Cloud Applications / How Do You Elevate Privileges On Vista At Runtime (2) (3) (4)

(1) (Reply)

Update Jtable At Runtime by jboy01(m): 9:29pm On Oct 27, 2013
pls am trying to update data table at runtime, but its not working.

the table named 'messageTable' was design in netbean with 4 columns. i want to update the table when the application load.
here is my code


public static void main(String args[]) {

try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainPage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainPage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainPage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainPage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainPage().setVisible(true);
}
});



DefaultTableModel model=new DefaultTableModel();
JTable messageTable= new JTable(model);

model.insertRow(0,new Object[]{"a","a","a","a"});
model.insertRow(1,new Object[]{"a","a","a","a"});

messageTable.repaint();



}
Re: Update Jtable At Runtime by javadoctor(m): 1:28am On Oct 29, 2013
I dnt seem to see any actionPerformed() on ur JTable, basically a table using a model to run wen initialized. If u using a modal to update the Jtable, create a method called updateTable() in d JFrame class,now create a JDialog class, the class should have a constructor with a this reference to the JFrame class.when u add a new row from the modal,d actionperformed method should make a call on ur JFrame class to call the updateTable() ,a method I feel which contains jTable.setModel(model) and jTable.repaint(), doing this effects changes on ur jtable

(1) (Reply)

Is NOUN Okay For A Programmer? {urgent} / MATLAB (Data Modeling, Analysis & Interpretation) Free 1-day Practical Workshop / Andela: Who Has Passed Stage 3 Of 44 Home Study Assessment?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 16
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.