Link to home
Start Free TrialLog in
Avatar of epifanio67
epifanio67

asked on

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...
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of epifanio67
epifanio67

ASKER

ok.... thx for your help...

Regards,
:)