How to resize the column in jtable using java tutorial


How to resize the column in jtable using java tutorial

This tutorial is all about How to resize the column in jtable using java tutorial. In this tutorial you will learn how to set the width of column in jtable using java that fit to your data in order to look better and to display the data properly in table. This tutorial uses JTable Components and Netbeans IDE. Please follow all the steps below to complete this tutorial.

How to resize the column in jtable using java tutorial Steps


First Create your project by clicking file at the top of your project and then click new project, you can name your project whatever you want. And then remove the default column by right clicking the table and the click table contents. Navigate to the column tab and then click all the default column and just delete by click the delete button and then close. After that copy and paste the code below




String sql = “SELECT company_id as ‘ID’,company_name as ‘Company Name’,email as ‘Email’,contact_no as ‘Contact’,address as ‘Address’ FROM company”;

pst = conn.prepareStatement(sql);

rs = pst.executeQuery();











}catch(Exception e){

JOptionPane.showMessageDialog(null, e);


[ /java]

You can resize the column by accessing its index.


table is the instance of your table , and the 3 is the index of the column

Note: column index always start at 0.


Run your project and see if it works.



For questions or any other concerns or thesis/capstone creation with documentation, you can contact me through the following:

E-Mail: [email protected]


Contact No.: +639098911050

Ryan A. Salem

BSIT Graduate, soon to be MIT.

Java Developer / System Developer

Related topic(s) that you make like:

1.) Create Login Form in Java
2.) Medical Store Management System using Java Netbeans


Looking for more source code? Type your keyword here here!


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.