Sunday, 15 September 2013

java - Filtering a JTable -


I am doing a computing project for which I need to make a jetty that can filter through one . I have been able to add a sort function but I am unable to add a function function. The closest example I can find is what I want to do, this is the TableFilters DOMO project in which it has the ability to launch and source code

I add it to the ability to filter my code Trying to piece the code

  import javax.swing *; Import java.awt. *; Import java.io * *; Import java.lang *; ////////////////// Import javax.swing.RowFilter; Import javax.swing.event. *; Import javax.swing.table.AbstractTableModel; Import javax.swing.table.TableRowSorter; Import java.awt.Dimension; Import java.awt.Component; ////////////////// Public Class Comprehensive {Jeffream Mymwindo = New JFram ("This is my title"); Jpnal firstpanel = new zpn (); // First panel components for a panel / first panel components JScrollPane myScrollTable; Public zero runGUI () {myMainWindow.setBounds (10, 10, 12, 756); // set position, then dimension myMainWindow.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); MyMainWindow.setLayout (new grid layout (1,1)); CreateFirstPanel (); // call method myMainWindow.getContentPane () to create each panel. Add (firstPanel); // mainWindow adds myMainWindow.setVisible (true) to TweakedPan; // reveal GUI} FirstPanel () {firstPanel.setLayout (null) to make public Zero; String [] aHeaders = {"athlete id", "foreman", "surname"}; String [] [] sampleData = new string [3] [3]; // rows, column sample data [0] [0] = "js 98"; SampleData [0] [1] = "John"; Sample data [0] [2] = "Smith"; Sample data [1] [0] = "db56"; Sample data [1] [1] = "David"; SampleData [1] [2] = "dog"; SampleData [2] [0] = "LL 86"; SampleData [2] [1] = "Lex"; Sample Data [2] [2] = "Luthor"; JTable myTable = new JTable (sampleData, aHeaders); MyTable.setAutoCreateRowSorter (true); // is sorted by a-z or 0- 9 in the column when a header is clicked on myScrollTable = new JScrollPane (myTable); MyScrollTable.setSize (1282,600); MyScrollTable.setLocation (0120); System.out.println ("Creating a comparison of the table"); FirstPanel.add (myScrollTable); } Public static zero main (string [] args) {CompFrame cf = new CompFrame (); Cf.runGUI (); }}  

I appreciate any help thank you

It is not perfect in any way, but provided you have a textfield that you can apply an action event, you can use a table sorter. It is not clear but it should work

  Public Zero searchable (string input) {final tablerosource & lt; TableModel & gt; Sorter = new tableros & lt; & Gt; (YourTable.getModel ()); AllEventsTable.setRowSorter (sorter); If (input.length ()! = 0) {Sorter. सर्त्रोफिल्टर (रोफफिल्टर.रेगक्सफिल्टर ("(? I)" + input)); } Other {sorter.setterfilter (empty); }}  

No comments:

Post a Comment