Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Display XML to JTable ?

  Asked By: Sean    Date: Jan 27    Category: Java    Views: 3681
  

iam want read the XML (DOM object)

display to the JTable Please Help me ?

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Latasha Wilson     Answered On: Jan 27

you should read  what you want from xml  node and in it's loop you can use this code that i put it for you


import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;

class AdvancedTableExample
extends JFrame
{
// Instance attributes used in this example
private JPanel topPanel;
private JTable table;
private JScrollPane scrollPane;

private String columnNames[];
private String dataValues[][];


// Constructor of main frame
public AdvancedTableExample()
{
// Set the frame characteristics
setTitle( "Advanced Table Application" );
setSize( 300, 200 );
setBackground( Color.gray );

// Create a panel to hold all other components
topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );

// Create columns
CreateColumns();
CreateData();

// Create a new table
instance
table = new JTable( dataValues, columnNames );

// Configure some of JTable's paramters
table.setShowHorizontalLines( false );
table.setRowSelectionAllowed( true );
table.setColumnSelectionAllowed( true );

// Change the selection colour
table.setSelectionForeground( Color.white );
table.setSelectionBackground( Color.red );

// Add the table to a scrolling pane
scrollPane = table.createScrollPaneForTable( table );
topPanel.add( scrollPane, BorderLayout.CENTER );
}

public void CreateColumns()
{
// Create column string labels
columnNames = new String[8];

for( int iCtr = 0; iCtr < 8; iCtr++ )
columnNames[iCtr] = "Col:" + iCtr;
}

public void CreateData()
{
// Create data for each element
dataValues = new String[100][8];

for( int iY = 0; iY < 100; iY++ )
{
for( int iX = 0; iX < 8; iX++ )
{
dataValues[iY][iX]
= "" + iX + "," + iY;
}
}
}


// Main entry point for this example
public static void main( String args[] )
{
// Create an instance of the test application
AdvancedTableExample mainFrame = new AdvancedTableExample();
mainFrame.setVisible( true );
}

 
Answer #2    Answered By: Ora Hanson     Answered On: Jan 27

U can do it in java script either:

http://www.codetoad.com/xml_javascript_data.asp

U can work on spreadsheets either:
www.ftponline.com/.../

 
Didn't find what you were looking for? Find more on Display XML to JTable ? Or get search suggestion and latest updates.




Tagged: