Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: header into header and table into table

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default header into header and table into table

    Hi, i have an idea for my program but i'm not able to realize it. Can someone help me?

    I have a list of users, and a list of match related to users. I want to make table that shown all users and all matches, like in the picture. I thought to make a table-into-table try because first two columns are sortable and, for that reason, i think that to make a single table is not a good solution. Updating matches with a single table will become harder and surely not object oriented.

    imgPng.jpg

    I want that the width of the green columns can be changed throught the title bar (red). My idea is

    1) To make a class (JuserMatchData) with a static DefaultTableColumnModel (headers) and

    2) call a JTable(TableModel dm, TableColumnModel JuserMatchData.headers) for every users. (Will this make the column width be syncronized?)

    3) To place a JTable without data on the TableColumnModel of the main table (black) to build the red header. To hide all headers of the "data table".

    [ 4) To add spoiler effect to hide matches ]

    Is there a better way to obtain the same results? Can my idea works or the width will not be syncd?


    //**//**//**//**//**//**//**//**//**//**//**//**//**
    CODE AND PROBLEMS WITH HEADERS
    //**//**//**//**//**//**//**//**//**//**//**//**//**

    I build the main table with userTable (that have only the first 2 columns filled) and userData.headers (described later).
    JTable(userTable, userData.headers);

    static userData.headers:
    headers = new DefaultTableColumnModel();
     
    col[0] = new TableColumn(0);
    col[0].setHeaderValue("Id");
    col[0].setMaxWidth(100);
    col[0].setPreferredWidth(50);
    col[0].setResizable(true);
     
    col[1] = new TableColumn(1);
    col[1].setHeaderValue("Nome");
    col[1].setPreferredWidth(200);
    col[1].setMaxWidth(200);
    col[1].setResizable(false);
     
    col[2] = new TableColumn(2);
    col[2].setHeaderValue(new JTable(3,1)); //test with an empty table
    col[2].setResizable(true);
     
    headers.addColumn(col[0]);
    headers.addColumn(col[1]);
    headers.addColumn(col[2]);

    The results :\
    nop.JPG

    PS: i have the same results even i do
    MYBLACKTABLE.setValueAt( new JTable(3,1), 0, 2);

    thanks for help
    Last edited by brazoayeye; August 3rd, 2014 at 01:26 PM.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,287
    My Mood
    Mellow
    Thanks
    252
    Thanked 777 Times in 762 Posts

    Default Re: header into header and table into table

    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

  3. #3
    Junior Member
    Join Date
    Aug 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: header into header and table into table

    Mmm , i can't understand the difference between [highlight=Java] and [code=Java] (the first is written in your link, i found the second previewing a new thread). Do you means that i have to quote all codes (in example MYBLACKTABLE.setValueAt( new JTable(3,1), 0, 2) even if it's a single line?

  4. #4
    Junior Member
    Join Date
    Aug 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: header into header and table into table

    more fails incoming.
    Here a new class


    public class JuserMatchData extends JTable implements TableCellRenderer {	
    	public DefaultTableModel tableModel;	
    	public static DefaultTableColumnModel columnModel;
    	public static TableColumn[] col = new TableColumn [4];
     
    	static {
     
    		columnModel = new DefaultTableColumnModel();
    		/* edit TableColumn and add to static columnModel */
    	}
     
    	JuserMatchData(){ //only head, for title
    		super( new DefaultTableModel(  ), columnModel);
    		tableModel = (DefaultTableModel) super.getModel();
    	}
     
    	JuserMatchData(user u){ //only body, for users
    		super( new DefaultTableModel(  ), columnModel);
    		tableModel = (DefaultTableModel) super.getModel();
    //HOW can i remove title?
    		tableModel.addRow(new Object[]{"IdL", "Sfid", "Gir", "Stat"});
    	}
     
     
    	@Override
        public Component getTableCellRendererComponent(JTable arg0, Object arg1,
        boolean arg2, boolean arg3, int arg4, int arg5) {
            return this;
        }
     
    }

    Now, in the code pasted in my first post i can replace the row
    col[2].setHeaderValue(new JTable(3, 1));
    // with
    col[2].setHeaderValue(new JuserMatchData());

    Here the result
    java.JPG
    (for testing purpose i placed a table even in the normal cell )

    If i add
    col[2].setCellRenderer(new JuserMatchData());
    col[2].setHeaderValue(new JuserMatchData());
    i have this result
    java.JPG

    If i undo and i add
    JUsers.setDefaultRenderer(JuserMatchData.class, new JuserMatchData());  //JUsers is the table posted
    //or 
    JUsers.setDefaultRenderer(JTable.class, new JuserMatchData());
    i have no changes, and i see the table like a string, like before.

    Thanks for helps

    PS:did u realized that i have to make 4 obj for my 4 column into an obj for the columnModel that, with an object for the tableModel, make my smaller table (class that implements TableCellRenderer and extend JTable) placed into the title of another TableColumn that is into a tableColumnModel that make another JTable (with its tableModel, ofc). Is theren't an easier way?
    Last edited by brazoayeye; August 5th, 2014 at 05:33 PM.

Similar Threads

  1. adding data in table but the table is in another frame
    By brianskiee in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 13th, 2014, 04:31 PM
  2. JavaMail - How do I get a specific Header of an Email?
    By gsanchezbiz in forum Java SE APIs
    Replies: 4
    Last Post: December 13th, 2011, 02:27 PM
  3. Customize Jtable header
    By md_suzon in forum AWT / Java Swing
    Replies: 1
    Last Post: October 11th, 2011, 05:16 PM
  4. JAAD ADTS Header Exception
    By Howie in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 15th, 2011, 11:49 AM
  5. JPCap TCP header encryption
    By proskopos in forum Java SE APIs
    Replies: 0
    Last Post: May 21st, 2011, 06:02 AM