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:
[java]
try{
String sql = “SELECT product_name as ‘Product Name’,company_name as ‘Company Name’,product_category as ‘Category’,quantity as ‘Quantity’ FROM products”;
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
while(rs.next()){
tableName.setModel(DbUtils.resultSetToTableModel(rs));
}
//code to change the background of a tableheader
JTableHeader theader = tableName.getTableHeader();
theader.setBackground(Color.CYAN);
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
[/java]
Take note that tableName is the variable of the table
Then you’re done, run your project and see if it works.
About The Change the background color of table header in table In Java
Project Name: | Change the background color of table header in table |
Language/s Used: | JAVA |
Database: | MySQL |
Type: | Desktop Application |
Developer: | IT SOURCECODE |
Updates: | 0 |
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