₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,327,062 members, 8,429,195 topics. Date: Thursday, 18 June 2026 at 02:49 PM

Toggle theme

Update Jtable At Runtime - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingUpdate Jtable At Runtime (1493 Views)

1 Reply

Update Jtable At Runtime by jboy01(op): 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

Windows Runtime ErrorsConpaas - An Open-source Runtime Environment For Cloud ApplicationsHow Do You Elevate Privileges On Vista At Runtime234

School App -- Free DownloadSimple Java ChallengeC++ Programmer Needed