Selasa, 19 Mei 2015

JAVA - How To Change A JTable Background Color, Font Size, Font Color In Java NetBeans

How To Set A Background Color, Font Size, Font Color To A JTable In Java

                                                                                    

In this java Tutorial you will see How You Can Change The BackGround Color Of  Your JTable And Font Size And Color (Foreground) In Java NetBeans .



*Java Courses Java Complete Course
                            Java Swing Course

Project Source Code:

package javaapp;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class JTableColor{
    
    public static void main(String[] args){
        
        JFrame frame = new JFrame();
        JTable table = new JTable();
        
        
        // create columns and rows to fill the jtable
        Object[] columns ={"ID","First Name","Last Name","Age"};

        Object[][] rows ={{"1","Java","JEE","11"},
                          {"2","CSharp","Asp","22"},
                          {"3","Php","Mysql","33"},
                          {"4","Html","Css","44"},
                          {"5","Jquery","JavaScript","55"},
                          {"6","Sql","Oracl","66"},
                          {"7","Ruby","Python","77"},
                          {"8","Xml","Xpath","88"}
        };   
        
        DefaultTableModel model = new DefaultTableModel(rows, columns);
        
        // set the model to the JTable
        table.setModel(model);
        
        // set a Background color to the Jtable
        table.setBackground(Color.decode("#058dc7"));
        
        // set Font To table
        table.setFont(new Font("", 1, 42));
        
        // set height to the table rows
        table.setRowHeight(50);
        
        // set color to the JTable Font
        table.setForeground(Color.white);
        
        JScrollPane pane = new JScrollPane(table);
        
        JPanel panel = new JPanel();
        
        panel.setLayout(new BorderLayout());
        
        panel.add(pane,BorderLayout.CENTER);
        
        frame.setContentPane(panel);

        frame.setSize(900,500);
        
        frame.setLocationRelativeTo(null);
        
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        frame.setVisible(true);
    }
}


///////////////OUTPUT:

JTable Java Background Color, Font Size, Font Color.jpg

Bagikan

Jangan lewatkan

JAVA - How To Change A JTable Background Color, Font Size, Font Color In Java NetBeans
4/ 5
Oleh

Subscribe via email

Suka dengan artikel di atas? Tambahkan email Anda untuk berlangganan.