Results 1 to 6 of 6
  1. #1
    orestis125 is offline Member
    Join Date
    Jun 2012
    Posts
    13
    Rep Power
    0

    Question Question about GUI

    Heya everyone,

    I'm new to this forum so please forgive me if I'm posting this in the wrong place. To explain this clearly, I'll post an image of what I'm trying to achieve:

    Question about GUI-capturehus.png

    Basically that's a GUI component like the JList but each row is made up of columns, which in this case they are called Packet, Source, Destination, Size and Function. Is there an easy way of adding such a component in my panel?

    Thank you very much,
    I appreciate your help

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default Re: Question about GUI

    A JTable?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    orestis125 is offline Member
    Join Date
    Jun 2012
    Posts
    13
    Rep Power
    0

    Default Re: Question about GUI

    Quote Originally Posted by JosAH View Post
    A JTable?

    kind regards,

    Jos
    Thank you for the reply, I didn't know about JTable.

    I'm not sure however, how I update the JTable's rows or add new ones after adding it onto the frame. I use a 2D array for the data and a 1D array for the columns; like this:


    String rowData[][] = {};
    String columnNames[] = {"Packet", "Destination", "Source"};
    TableModel tableModel = new DefaultTableModel(rowData, columnNames);
    JTable table = new JTable(tableModel);

    public SnifferGUI() {

    add(table);
    }
    Could you give me a hint on how to add/update rows of the JTable?
    Thank you very much

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default Re: Question about GUI

    Have you read what a DefaultTableModel can do for you?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    orestis125 is offline Member
    Join Date
    Jun 2012
    Posts
    13
    Rep Power
    0

    Default Re: Question about GUI

    Thank you for the reply,

    I've found a way to dynamically update the table and to make the column names show up but for some reason 1 out of 2 times I run the program, the table doesn't appear at all. This is very weird since this happens at random. This is what I use:

    tableModel.addColumn("Packet");
    tableModel.addColumn("Destination");
    tableModel.addColumn("Source");
    tableModel.addRow(new String[]{"1","192.168.0.15","64.55.13.0"});
    add(table);

    Any idea why that might be? I appreciate your help so far.

    Thank you very much again
    Last edited by orestis125; 06-04-2012 at 10:25 PM.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: Question about GUI

    Quote Originally Posted by orestis125 View Post
    for some reason 1 out of 2 times I run the program, the table doesn't appear at all. This is very weird since this happens at random.
    Usually a concurrency issue. You have to respect Swing's single threaded rule. Go through this Tutorial Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 2
    Last Post: 05-25-2012, 04:00 PM
  2. Java Question [Beginner Question]
    By joker760 in forum New To Java
    Replies: 3
    Last Post: 12-13-2011, 04:01 PM
  3. question posted by indissa: library question.
    By Fubarable in forum New To Java
    Replies: 2
    Last Post: 11-18-2011, 01:14 AM
  4. Question concerning question marks and colons
    By jim01 in forum New To Java
    Replies: 17
    Last Post: 01-14-2011, 12:05 AM
  5. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •