Affichage des articles dont le libellé est JTable Foreground. Afficher tous les articles
Affichage des articles dont le libellé est JTable Foreground. Afficher tous les articles

Java JTable Style

How To Style A JTable Using Java NetBeans

JTable Style In Java



In this Java Tutorial we will see How To Style The Jtable By Changeing Row Height, Show Grid, Set Grid Color, Set Background, Set Foreground, Set Selection Background,  Set Selection Foreground, Set Font In Java NetBeans .




Project Source Code:


        jTable1.setRowHeight(40);
        //jTable1.setRowHeight(1, 100);

        jTable1.setShowGrid(true);
        jTable1.setGridColor(Color.red);

        jTable1.setBackground(Color.BLACK);
        jTable1.setForeground(Color.WHITE);
        
        jTable1.setSelectionBackground(Color.WHITE);
        jTable1.setSelectionForeground(Color.BLACK);
        
        jTable1.setFont(new Font("Comic Sans MS", Font.ITALIC, 20)); 


OutPut:

Style JTable Using Java




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 .


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