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.


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

Results 1 to 2 of 2

Thread: JTable

  1. #1
    Junior Member
    Join Date
    Dec 2020
    Thanked 0 Times in 0 Posts

    Default JTable

    Hi. I'm using JTable with DefaultTableModel. How do you change the width of some specific columns? Thank you.

  2. #2
    Member Helium c2's Avatar
    Join Date
    Nov 2023
    Kekaha, Kaua'i
    Thanked 0 Times in 0 Posts

    Default Re: JTable

    // Packages to import
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;

    public class JTableExamples {
    // frame
    JFrame f;
    // Table
    JTable j;

    // Constructor
    // Frame initialization
    f = new JFrame();

    // Frame Title
    f.setTitle("JTable Example");

    // Data to be displayed in the JTable
    String[][] data = {
    { "Kundan Kumar Jha", "4031", "CSE" },
    { "Anand Jha", "6014", "IT" }

    // Column Names
    String[] columnNames = { "Name", "Roll Number", "Department" };

    // Initializing the JTable
    j = new JTable(data, columnNames);
    j.setBounds(30, 40, 200, 300);

    // adding it to JScrollPane
    JScrollPane sp = new JScrollPane(j);
    // Frame Size
    f.setSize(500, 200);
    // Frame Visible = true

    // Driver method
    public static void main(String[] args)
    new JTableExamples();


    j.setBounds(x,y,x,y) // you can see that the boundary of the table already automatically adjust the table to your liking. Whatever you type in. This is a program that makes this table. Okay. But you know how a Java printout looks like right?
    Last edited by Helium c2; November 23rd, 2023 at 04:37 PM. Reason: spelling

Similar Threads

  1. Replies: 0
    Last Post: October 4th, 2017, 12:24 PM
  2. Replies: 1
    Last Post: February 5th, 2014, 09:22 AM
  3. Replies: 21
    Last Post: November 27th, 2012, 10:58 PM

Tags for this Thread