Change the background color of table header in table using Java Tutorial

0
30

Change the background color of table header in table using Java Tutorial

This tutorial is all about Change the background color of table header in table using Java Tutorial. In this tutorial you will learn how to Change the background color of table header in table using Java Tutorial. Sometimes you need to change the background color of your table header in order to make your table more presentable and user friendly. it helps the users to better understand your system and to be more attractive. Please follow all the steps below to complete this tutorial.

 

Change the background color of table header in table using Java Tutorial steps

First of all, you must create your project by clicking File at the top left of your netbeans and the new project. You can name you project whatever you want. After creating project, the next is to create your own jframe form by right clicking the Source Packages and then clicking New JFrame Form, Drag one table and copy and paste the code below:

 

  1. try{
  2.  
  3. String sql = "SELECT product_name as 'Product Name',company_name as 'Company Name',product_category as 'Category',quantity as 'Quantity' FROM products";
  4.  
  5. pst = conn.prepareStatement(sql);
  6.  
  7. rs = pst.executeQuery();
  8.  
  9. while(rs.next()){
  10.  
  11. tableName.setModel(DbUtils.resultSetToTableModel(rs));
  12.  
  13. }
  14.  
  15.  
  16.  
  17. //code to change the background of a tableheader
  18.  
  19. JTableHeader theader = tableName.getTableHeader();
  20.  
  21. theader.setBackground(Color.CYAN);
  22.  
  23.  
  24.  
  25. }catch(Exception e){
  26.  
  27. JOptionPane.showMessageDialog(null, e);
  28.  
  29. }

 

Take note that tableName is the variable of the table

 

Then you’re done, 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]

Facebook: facebook.com/RyyanSalem

Contact No.: +639098911050

Ryan A. Salem

BSIT Graduate, soon to be MIT.

Java Developer / System Developer

Related topic(s) that you make like:

1.) Automated Payroll System using Java
2.) How to resize the column in table using Java

Facebook Comments
(Visited 38 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here