File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Nested JTables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Nested JTables" Watch "Nested JTables" New topic
Author

Nested JTables

seema prakash
Ranch Hand

Joined: Nov 17, 2004
Posts: 59
Is it possible to have a nested JTable?
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
yes
seema prakash
Ranch Hand

Joined: Nov 17, 2004
Posts: 59
Don, Thanks a lot for the answer.
I have another question.
I have a class written to display each of the cell as a text area.
What do I have to do if I need to insert a table in this text area? Please help.
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
Why do you want to put a JTable in a JTextArea? That doesn't really make sense to me. What are you trying to achieve ?
seema prakash
Ranch Hand

Joined: Nov 17, 2004
Posts: 59
The main question is I would like to know if we can have a table in the cell of another table. Is it possible ?

This is an example from the internet.

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 parameters
table.setShowHorizontalLines( false );
table.setShowVerticalLines(false);
table.setRowSelectionAllowed( true );
table.setColumnSelectionAllowed( true );

// Change the selection color
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 );

}

}

Now I want to create each cell as a table. Is it possible? and how do I acheive this?
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
If you want a cell to look like a JTable, you need to write a TableCellRenderer. I suggest you write a class thus :



You then need to implement the getTableCellRendererComponent() method.

hth.
D.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Nested JTables