0

I create a jtable like this :

enter image description here

String name = temp.getName();
String enemy = namaFileUtama.toString(); 
DefaultTableModel models = (DefaultTableModel) Main_Menu.jTable4.getModel();
            List<ReportMomentOfTruth> theListRMOT = new ArrayList<ReportMomentOfTruth>();
            ReportMomentOfTruth rmot = new ReportMomentOfTruth();
            rmot.setNameOfMainFile(name);
            rmot.setNameOfComparingFile(enemy);
            theListRMOT.add(rmot);

            for (ReportMomentOfTruth reportMomentOfTruth : theListRMOT) {
                models.addRow(new Object[]{
                    reportMomentOfTruth.getNamaFileUtama(),
                    reportMomentOfTruth.getNamaFilePembanding(),
                });
            }

You know, I dont get an idea. How can I get the contains the file if I click one row in jtable then the contains will be show in jTextArea ? Any suggestion ? any example perhaps ? Thanks

edit

You know, I am using netbeans, I can get a method like this

private void jTable4MouseClicked(java.awt.event.MouseEvent evt) {                                     
    if (evt.getClickCount() == 1) {

    }
} 

Now how to ?

user2971238
  • 95
  • 1
  • 2
  • 9
  • You want to display a file content in one column of JTable or want to display content in JTextArea got from one column of JTable. – Braj Jul 27 '14 at 13:26

1 Answers1

3

How can I get the contains the file if I click one row in jtable then the contains will be show in jTextArea?

You can better use JEditorPane that has a method setPage() that can be used to initialize the component from a URL.

Just get the values of selected row and use below code to set the content in JEditorPane.

sample code:

final JEditorPane document = new JEditorPane();
document.setPage(new File(".../a.java").toURI().toURL());

Add ListSelectionListener to detect the selection change event in the JTable

final JTable jTable = new JTable();
jTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
      int row = jTable.getSelectedRow();
      if(row != -1){
         String firstColumnValue = jTable.getModel().getValueAt(row, 0).toString();
         String secondColumnValue = jTable.getModel().getValueAt(row, 1).toString();
         // load the JEditorPane
      }
    }
});;

Read more...

Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76