Note that there are some explanatory texts on larger screens.

plurals
  1. POArraylist to 2D array and then to a JTable
    text
    copied!<p>i'm struggeling to make my arraylist into an 2D array and then adding it on a table to show the data. </p> <pre><code>import java.awt.*; import javax.swing.*; import java.util.ArrayList; import java.util.List; public class Planettabell { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { JFrame vindu = new Test(); vindu.setVisible(true); } }); } } class Test extends JFrame { private String[] name = {"Name", "grade"}; Object[][] cell = {{"nameHer", "GradeHer"}}; Object[][] cell2 = {{"nameHer2", "gradeHer2"}}; Object[][] cell3 = {{"nameHer3", "gradeHer3"} }; public Test() { setTitle("Planettabell"); setSize(500, 210); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); List&lt;Object[]&gt; list = new ArrayList&lt;Object[]&gt;(); list.add(cell); list.add(cell2); list.add(cell3); Object[][]array = list.toArray(new Object[list.size()][]); JTable tabell = new JTable(array, name); Container c = getContentPane(); c.setLayout(new FlowLayout()); c.add(new JScrollPane(tabell), BorderLayout.CENTER); } } </code></pre> <p>i will get this message if i run it <code>Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1</code></p> <p>this code is working if i add 'cell' instead of 'array' on JTable, but i need the entire array from list to work. </p> <p>i have also tried:</p> <pre><code> int number = list.size()/2; Object[][] ArrayNew = new Object[number][2]; for(int x = 0; x&lt; number; x++) { for(int z = 0; z &lt; 2; z++) { int y = 2 * x; ArrayNew [x][z] = list.get(y+z); } } JTable tabell = new JTable(ArrayNew, name); </code></pre> <p>instead of list.toarray. But then i only gett [[Ljava.lang.Object;@28864ae7 and [[Ljava.lang.Object;@49214a13 where the text in the table supposed to be.</p> <p>would appreicate any answer :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload