[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 538
  • Last Modified:

Java: how to convert list array values to Object[][] to create table object?

Hello Experts,

is there a way to convert list array to Object[ ][ ] to construct table object?

public static void main(String args[]) {

	Pattern p = Pattern.compile("Sip\\w*");

	String file = "message SipRoute test in SipUser " + "\n"
		+ "receipt SipCall at time SipUpdate " + "\n"
		+ "message SipReg during SipDiv " + "\n";

	ArrayList<String> list = new ArrayList<String>();
	Object obj[] = null;

    	Matcher matcher = p.matcher(file);
    	while(matcher.find() == true){
    		list.add(matcher.group());
	}

	Object[]lArray = list.toArray(); //SipRoute, SipUser, SipCall, SipUpdate, SipReg, SipDiv
	Object[][] data = new Object[][]{ lArray };
	String[] headers = { "myColTitle" };
			
	JFrame frame = new JFrame("test");
			
	JTable table = new JTable(data, headers);
        JScrollPane scrollPane = new JScrollPane(table);
        table.setFillsViewportHeight(true);
	        
        frame.getContentPane().add(scrollPane,BorderLayout.CENTER);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(550, 200);
        frame.setVisible(true);

 

			
  }

Open in new window


Below is table constructor:
JTable(Object[ ] [ ] data, Object[ ] header)

Thanks for your help...
0
epifanio67
Asked:
epifanio67
  • 2
1 Solution
 
CEHJCommented:
String[] headers = { "myColTitle" };

Open in new window


You're about to repeat your previous error that i already corrected!

http://docs.oracle.com/javase/6/docs/api/javax/swing/JTable.html#JTable(java.util.Vector, java.util.Vector)

is what you want
0
 
epifanio67Author Commented:
ok.... thx for your help...

Regards,
0
 
CEHJCommented:
:)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now