4 Replies - 8880 Views - Last Post: 02 July 2011 - 03:13 PM Rate Topic: -----

#1 raghav.purankar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 01-May 11

how to display text file in jtable using netbeans IDE

Posted 02 July 2011 - 12:43 AM

my design in netbeans ide is having a code as follows:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Testing.java
 *
 * Created on Jul 2, 2011, 10:27:52 AM
 */
package raghav;

/**
 *
 * @author Dhananjay RAje
 */
public class Testing extends javax.swing.JFrame {

    /** Creates new form Testing */
    public Testing() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(18, 18, 18)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(475, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(27, 27, 27)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(36, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Testing().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration
}



my IDE contains following component :
1. jtable(five cols,variable number of rows).
now my txt file is:
contigID SequenceLength Numreads
>contig00001 length=586 numreads=4
CGGGAAATTATCcGCGCCTTCACCGCCGCCGGTTCCACCGACGAACGGATACTGCGtGaa
ggCCGCGATCCCGTCggaCGGAAAaCGCCcTGGCCCGGGAaCATACCGTTCGGGCCGCCA
AGTGTTATAGCCGGACCACTTGTCAGAACATTTCCaaTCCGAAGATGTGAGTtCGGAAGg
TAAAAGCCCGACAAGTTGCGCGgTGAATTTACCTTtACcGCACGATATGCGTCCGTATTA
AaGAAAaGTTCGAAATTATCAGTAAGGCCGACCTGAAaGCTGACCGGGAGTTCAACAAAA
TCTGCATCACCcGGgTCACGGTCGAAATTGCTGTACGCGGCGCTGAACGTAAATTCACCC
TTTcTAAGGGTGTCGCcGTCGTAAACCGTAAaCAaGCCGGTAGCGCCGCCCATCGGGCCG
CCGGTACCAACCGTCGGTGCCGTGTTTCTtGCATCATTGTCCGATCGAGCGTTCTCGTCC
GCTTGTGCAAaTCCTGCAaTAGCTAACGTGAAAACGATCAGAGCTGTTGTAAATACTCTA
TAAGCGAGATTCATCACATTCCTCcGCCGAAATAAAAAGTTAATTt

>contig00002 length=554 numreads=4
TGCGCCAaCCGCGCTCTtCATAAaTGGGCACTGCTCCCGATGGCCgACTCGGGCGGTTCG
CCATGAGATCTTTGCCtACCcAGgAaCtCACcACCAAGTCTGATTGCTGTGTGTTTtCTT
CAAGTCCCTATTTCTATTCtCTTtAATGGAACCCGTAGGAAACCCGTGTAGGACGCGGGA
aCCGCACTTgAAGGGGGAGGCGCGGGGTACCGGtCCGGGAACGTACGGGTACCGGCGGGG
gAGGGGAGGGGGACCgCTCCGGGAAGGCCAGGGGACGGATTGGGGAAGGgCGGGTACCGA
AGCGGGgAAaTGGGggAaCcGGCGAGAGGGTTCCTCGCTAAGTGGGGGAAATaGGGGAAA
GGTTGACCAGTGGTtCCCcGCTCTCGTAACATGCCTCAGATAGCGCCATCCGCTGTACCT
GGtcaggtcGctggcaacttcggccgagcaggtgaacccgaaaggtgagggtcagtgtga
cacaccaaccgaacaccgacgaggcaagcgtaggagccggcgtggccgcgcccggcggcg
ctgaggactcctcg

here i want to display data field named as "contig0001"in contigID column and "length" field in seqlength column in jtable.
column sequence are as follows:
contigID Description SeqLength Organism GC_percent

what provision i have to made in netbeans IDE.
please help me?
thanks

Is This A Good Question/Topic? 0
  • +

Replies To: how to display text file in jtable using netbeans IDE

#2 immeraufdemhund  Icon User is offline

  • D.I.C Regular

Reputation: 79
  • View blog
  • Posts: 495
  • Joined: 29-March 10

Re: how to display text file in jtable using netbeans IDE

Posted 02 July 2011 - 04:57 AM

netbeans doesn't offer anything special, but the File class does. to get the contigID you'd probably could try this

File contigFile = new File("c:\\contig0001.txt"); //just an example
String contigID = contigFile.getName();
int contigLengh = contigFile.length();



see if something like that doens't help you in your quest.
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10561
  • View blog
  • Posts: 39,083
  • Joined: 27-December 08

Re: how to display text file in jtable using netbeans IDE

Posted 02 July 2011 - 12:03 PM

Due to the horrid, unmaintainable code the NetBeans GUI Builder produces, we do not support it. However, you can create a new JTable with a DefaultTableModel with the given data. Or you can use the JTable setValueAt(row, col, value) method.
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,432
  • Joined: 20-September 08

Re: how to display text file in jtable using netbeans IDE

Posted 02 July 2011 - 02:54 PM

Try something like the following:



import java.awt.*;
import java.awt.event.*;

import java.io.*;

import java.util.*;

import javax.swing.*;
import javax.swing.table.*;


public class F extends JFrame {
    private void setGui() {
	try {
	    setLocation(0, 100);
	    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    Container cp = getContentPane();
	    cp.add(getTable());
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }

    private Component getTable() {
	String[] headers = { "ContigID", "Length" };
	DefaultTableModel dtm = new DefaultTableModel(getDataVector(), new Vector<Object>(Arrays.asList(headers)));
	return new JScrollPane(new JTable(dtm));
    }

    private Vector<Vector<Object>> getDataVector() {
	Scanner s = null;
	Vector<Vector<Object>> data = new Vector<Vector<Object>>();
	try {
	    s = new Scanner(new File("gattaca.txt"));
	    while (s.hasNextLine()) {
		String line = s.nextLine();
		if (line.startsWith(">")) {
		    String[] atoms = line.split("[> =]");
		    Vector<Object> row = new Vector<Object>();
		    row.add(atoms[1]);
		    row.add(atoms[3]);
		    data.add(row);
		}
	    }
	}
	catch(IOException e) {
	    e.printStackTrace();	
	}
	finally {
	    if (s != null) {
		s.close();
	    }
	}
	return data;
    }

    public static void main(String[] args) {
	try {
	    SwingUtilities.invokeAndWait(new Runnable() {
		public void run() {
		    F f = new F();
		    f.setGui();
		    f.setSize(200, 200);
		    f.setVisible(true);
		}
	    });
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }
}

Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: how to display text file in jtable using netbeans IDE

Posted 02 July 2011 - 03:13 PM

Your topic title might shows that you really have a misunderstood concept here:

NetBeans is just a fancy Editor to let you edit/compile Java code
You do not "display test file in JTable using Netbeans"
you write JAVA code using NetBeans to do whatever you want

You can cut & paste that code and use Notepad and compile on line and you should have the same results
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1