• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Nested JTables

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to have a nested JTable?
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes
 
seema prakash
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic