Steps to Change Dark Theme to Light Theme in Visual Studio Code

If you like Light Theme in Code Editor in Visual Studio Code then here SKOTechLearn will describe the steps to Change Dark Theme to Light Them in Visual Studio Code. And Here we will also describe the steps to Customize Color or Theme in Visual Studio Code.

Dark theme to Light Theme in Visual Studio Code

By default VS Code contain Dark theme. You know that Visual Studio is highly customized code editor compare to all other code editor. And you can find many feature to change Look and Feel in Visual Studio Code.

Change visual studio code background color

Now, we can choose any one process for Change Code Editor Color in Visual Studio Code:

  1. Change Theme of Visual Studio Code through Shortcut Key
  2. Change Theme of Visual Studio Code through Settings
  3. Change Color Theme of Visual Studio Code through Code


(1). Change Theme of Visual Studio Code through Shortcut Key:

When you open VSCode, and want to change theme, then simply you have to press two different shortcut Key one by one same time.

Press First Shortcut Key:  CTRL + K 
After that Press second Shortcut Key:  CTRL + T 

Now, you will see a drop down Option Box “Select Color Theme (Up/Down Keys To Preview)” will appear containing list of existing theme like bellow:

Change Theme in Visual Studio Code through Shortcut Key

This Option Box contain two types of Theme Category first is “light themes” and second is “dark themes”. If you want to change VSCode in light theme, then choose first category.


(2). Change Color Theme of Visual Studio Code through Settings:

If you want to proceed for color change through VSCode settings, then you have to follow the steps:

1.
First Go to “File” menu.

2.
Find “Preferences” and select it.

3.
And then select “Color Theme[Ctrl+K Ctrl+T]” option from it.

4.
Now, a drop down list will appear containing themes options. Choose anyone which you like.

Settings to change Theme color in Visual Studio

As you can see, in this way you can change Dark Theme to Light Theme in VSCode.

(3). Change Color Theme of Visual Studio Code through Code:

This is very interesting process to Change Look and Feel Of Visual Studio Code. In this Process you can change every Part of VSCode Tool's color according to your desire. You have to Simply proceed with following way:

1.
Same as above given steps, you have to first go to “File” menu then “Preferences” then “Settings”.

2.
You will find “Settings” Tab will appear. Go to Search Bar and search for “.json”.

3.
You will get “Edit in Settings.json” option. Just click on it.

4.
Now “Settings.json” file will display. Add color code like bellow:

{
     "workbench.colorCustomizations": {
     //For Code editor Color Change
     "editor.background": "#edeafa",
     "editor.foreground": "#4b4548",

     //For Sidebar Color Change
     "sideBar.background": "#fddcaa",
     "sideBar.foreground": "#612144", 

     //Change Activity Bar Color
     "activityBar.background": "#7f61a7",
     "activityBar.foreground": "#c5ff3e",
     "activityBar.inactiveForeground": "#6dc58f"
     }
} 

After writing this code, save it and see what happen:
Customise Theme Color in Visual Studio Code

As you can see you can manually create theme in VSCode.

So, this way you can easily Customize Theme Color of Visual Studio Code. And also set Light theme in VSCode.

Steps to Get Entry Or Text Value in Label in Python Tkinter

In python using Tkinter, there are two types of Input Box first is Tkinter Entry Box and Second is Tkinter Text. And if you want to get String or Get Value from Entry in Tkinter or Get Tkinter Text Value in Python then here you will find detailed process to consider how to use it in your Project.


How to use Tkinter Label in Python with features


Important Note: We Find that Text widget can not work in Tab Order. You have to write more code effort to perform Tab order in Text in Tkinter. But if you use Entry widget in python. There will no problem in tab order.

Now Let’s Learn How to Get Value from Entry in Python Tkinter or Get Value from Text with following way:

  1. Get Entry Value in Label in Python Tkinter
  2. Get Text Value in Label in Python Tkinter

So, Let’s Start.

(1). Get Entry Value in Label in Python Tkinter :

As you know that for perform any action in Python you have to define Function. So for getting value you have to define function as bellow and Get Entry Value.

Python Code:
from tkinter import *

MyRootDialog=Tk()
#Set Tkinter Size And Location
MyRootDialog.geometry("200x150+100+100")

#Set Tkinter Title
MyRootDialog.title("Get Input Value in Label")

# Define Function for get Value
def Get_MyInputValue():
     getresult = MyEntryBox.get()
     myTKlabel['text'] = getresult

# Create Tkinter Entry Widget
MyEntryBox = Entry(MyRootDialog, width=20)
MyEntryBox.place(x=5, y=6)

myTKlabel = Label(MyRootDialog, borderwidth=1, relief="ridge", height=3, width=25)
myTKlabel.place(x=4, y=42)

#command will call the defined function
MyTkButton = Button(MyRootDialog, height=1, width=10, text="Get text", command= Get_MyInputValue)
MyTkButton.place(x=4, y=112)

mainloop()

One more thing here you can use get value in Label through following two way:

myTKlabel['text'] = getresult

or

myTKlabel.config(text = getresult)

You can use it according to your desire. Both will present same result.

Output:
Get Entry value in Tkinter in Python

You can also Set Tkinter window in Center Location.

(2). Get Text Value in Label in Python Tkinter :

Now if you use Tkinter Text widget in python then you have to write following code to get Tkinter text in python.

Note: Get Value from Tkinter Entry Widget code: MyEntryBox.get()
And for get Value from Tkinter Text Widget code: MyTktextBox.get("1.0", 'end-1c')

In Text Widget you have to pass Index inside Get() function:

Code:
from tkinter import *

MyRootDialog=Tk()
#Set Tkinter Size And Location
MyRootDialog.geometry("200x150+100+100")

#Set Tkinter Title
MyRootDialog.title("Get Input Value in Label")

# Define Function for get Text Value
def Get_TKTextValue():
      myTxtresult = MyTktextBox.get("1.0", 'end-1c')
      myTKlabel.config(text = myTxtresult)

# Create Tkinter Text Widget
MyTktextBox=Text(MyRootDialog, height=1, width=20)
MyTktextBox.place(x=5, y=6)


myTKlabel = Label(MyRootDialog, borderwidth=1, relief="ridge", height=2, width=25)
myTKlabel.place(x=4, y=42)

#command will call the defined function
MyButton = Button(MyRootDialog, height=1, width=10, text="Get text", command= Get_TKTextValue)
MyButton.place(x=4, y=92)

mainloop()

Now, when you run you code, this will present following output.


Different types of Multi Line String process in Python


Output:
Get Text Value in Python

So, these above given code process is use to Get Tkinter Text Value in Label or Get Entry Value in Python.

String in Python with Single, Multi-Line, Concatenate in Python

First of all you have to understand about String in Python. Basically a String is a collection of characters which is used to define a word or sentence or paragraph with single or multiple lines. And here we also describe some basic Format of String or Integer Concatenation in Python.

Use String in Python

In Python, when we define a string, it will be define either Single (‘ ’) Quote or Double Quote ( “ ”).
For simple example you can use print() function for display simple word or sentence as form of string as given bellow:

print( "SKOTechLearn" )
print( 'SKOTechLearn' )
Output:
>>>
SKOTechLearn
SKOTechLearn
>>>


So, let’s see the types and use of String with following way:

  1. Single Line String using Variable 
  2. Use String to Passing value in Function 
  3. Multi-Line Sting using Variable 
  4. Concatenate Strings in Python 
  5. Concatenate integer or number with String


(1). Single Line String in Python using Variable :

Suppose you want to store your word or sentence and show during process then we simply assign a Variable.

mystrng = "Hello SKOTechLearn"
print(mystrng)
Output:
>>>
Hello SKOTechLearn
>>>


(2). Use String to Passing value in Function in Python:

This is very important point which is used in every programming process. Here you can use string for passing in other function or references.

You can simply cover following points:

➤ Python pass function as argument with parameters
➤ How to pass string as parameter in python function?
➤ Python pass function name as argument
➤ Python call function from string with arguments

You have to simply learn following process:

Myfstr = "skotechlearn"
MyPFunc( Myfstr )

def MyPFunc ( Myfstr ):
    # upper() method is use to show Characters in Capital Letters
    skstr = Myfstr.upper()
    print (skstr)
Output:
>>>
SKOTECHLEARN
>>>

You can simply use this process with many ways according to your application requirement process.


(3). Multi-Line Sting in Python using Variable :

As you can understand how to store or show string in python, but when you want to store multiline sentence or paragraph on your application, what is the code process we apply?

You have to simply write word or sentence in start and end with Triple Quotes (""" """) or You can simply use “\n” between you sentence with following way:

Multi-line String using Triple Quotes (""" """) :

MyMultilineStr = """This is Triple Quote multiline Sentence
Using Python Code
With Simple output"""
print (MyMultilineStr)
Output:
>>>
This is Triple Quote multiline Sentence
Using Python Code
With Simple output
>>>


Multi-line using “\n” :

MyNextLineStr = "This is multiline Sentence \n Python Code \n With Next Line Process "
print (MyNextLineStr)
Output:
>>>
This is multiline Sentence
Python Code
With Next Line Process
>>>


(4). Concatenate Strings in Python :

There are 4 ways for concatenating string in Python.

First Process:


You can simply use “+” Sign for concatenate word or sentence.

FstStr = "SKO"
SecStr = "Tech"
ThirdStr = "Learn"

FinalStr = FstStr  + " " + SecStr + " " + ThirdStr
print (FinalStr)
Output:
>>>
SKO Tech Learn
>>>


Second Process:


You can simply use “{}{}{}”.format(StrVar1, StrVar2, StrVar3) function.

Tips1: "{}{}{}".format(StrVar1, StrVar2, StrVar3): if you don’t need space between string.
Tips2: "{} {} {}".format(StrVar1, StrVar2, StrVar3) : if you need to add space between string.

Note: Input Number of “{}” Curly Brace according to the number of string variable.

PStr1= "SKO"
PStr2 = "Tech"
PStr3 = "Learn"
PStr4 = "Tips"

#concatenate String without space
print("{}{}{}{}".format(PStr1, PStr2, PStr3, PStr4)) 

# concatenate String with space
print("{} {} {} {}".format(PStr1, PStr2, PStr3, PStr4))
Output:
>>>
SKOTechLearnTips
SKO Tech Learn Tips
>>>


Third Process:


In this process you can use "% s % s % s" % (StrVr1, StrVr2, StrVr3). Here you can add number of “% s” according to number of string value or variable.

"% s % s % s" : if you want to add space during concatenating variable. This will show sentence with space.
"% s% s% s" : This will show Concatenate variable without space.

For Example:
myVr1 = "This"
myVr2 = "is"
myVr3 = "Concatenate"
myVr4 = "Code"
#Sentance without space
print("%s%s%s%s" % (myVr1, myVr2, myVr3, myVr4)) 

# Add space between word or sentence
print("%s %s %s %s" % (myVr1, myVr2, myVr3, myVr4))
Output:
>>>
ThisisConcatenateCode
This is Concatenate Code
>>>


Forth Process:


Use .join for concatenate in python. For Simply you have to follow following syntax:

Concatenate Without Space: "".join([SkVr1, SkVr2, SkVr3])
Concatenate With Space: "".join([SkVr1, SkVr2, SkVr3])

For Example:
SkVr1 = "Learn"
SkVr2 = "Concatenate"
SkVr3 = "process"
# Concatenate process without space
print("".join([SkVr1, SkVr2, SkVr3])) 
# Concatenate process with space 
print(" ".join([SkVr1, SkVr2, SkVr3]))
Output:
>>>
LearnConcatenateprocess
Learn Concatenate process
>>>


(5). Concatenate integer or number in Python with String:

When you will try to concatenate integer in Python with alphabet or sentence, you will get the following error with normal process like bellow:
print(1 + "This is Alphabet")
>>>
Traceback (most recent call last):
 print(1+"This is Alphabet")
TypeError: unsupported operand type(s) for +: 'int' and 'str
>>> 

As you can see the above error will display. So, we try following way to solve this problem. There are four process for Concatenating Integer with String:

Process 1:
 Simply input number inside Double Quote(“ ”):

print("2"+ ". This is Alphabet")
Output:
>>>
2. This is Alphabet
>>>


Process 2:
 Using str() for converting Integer :

mynum = 2
combstr = "This is Alphabet"
print(str(mynum) + "=  " + combstr)
Output:
>>>
2= This is Alphabet
>>>


Process 3:
 Using .format method for concatenate of integer :

mynum = 2
combstr = "This is Alphabet"
print "Point No. {} is - {} for concatenate with Integer".format(mynum, combstr)
Output:
>>>
Point No. 2 is - This is Alphabet for concatenate with Integer
>>>


Process 4:
 Using “% s” for Concatenate integer :

mynum = 2
combstr = "This is Alphabet"
print("No. % s % s" % (mynum, combstr))
Output:
>>>
No. 2 This is Alphabet
>>>


So Friends, these are the process for Using String in Python, easily show Multi-line String in python, Passing String in function in Python, Concatenate String in Python, Concatenate Integer in Python.

Static or Dynamic Way to Display Image in jFrame in Java Swing

In this post, SKOTechLearn describe the static and dynamic way to Display Image in jFrame in Java Swing with Netbeans through jLabel. Simply we can add image through Properties Settings or using Code which is described bellow.

Why we use jLabel for displaying image? Because, This is the simple way to handle any files like: jpeg, png etc using jLable pallet.

Open jFrame through Another jFrame in Java Swing

If you want to show external image or use it as internal way like add as logo or banner, then here we will describe as dynamic and static way. So lets learn with following two process:


Come to the point by point description.

(1) Display Image in jLabel in Java Swing Static way :

In this process just create an image file or use your existing file and copy that file in your particular package. For this step by step process let's find following.

Suppose if you create a picture file and want to show. Then first copy that particular file and paste it on your project's package, or you can access through external path.
Drag_Image_File_In_Java_Package
Drag Image File In Package

Tips to Auto Resize Control Setting in Java Netbeans

As you can see, I simply copy my particular file and paste on my package. After that simply drag a jLabel from palette and adjust it's height width and location according to desire and after that follow the steps:


1.
Right click on jLabel.

2.
Select 'Properties' option or go to directly on 'Properties' window.

3.
Find “icon” option. And select your particular file.

4.
If it not show any file just click on 'Custom editor' buttonCustom_Editor_Buton_in_Java

5.
And select file from there.


For 'Custom editor' button, you can see that it will contain with icon's option of Properties windows. For easily understanding process follow the image.
Set_Icon_in_jLabel
jLabel icon setting

When you done all this process. It will display picture like shown in above figure.
So, this is the way of showing picture in static way.

How to Design or Change Look of jLabel in Java in Netbeans


(2) Display Image in jLabel in Java Swing Dynamic way:

If you want to show image in dynamic way, you have to write code for it, Suppose you want to show picture during jFrame's open or activate. So write code as we describe bellow.

But first, you have to import some class inside your java Package:
package simple_java; 

  import java.awt.image.BufferedImage;
  import java.io.IOException;
  import javax.imageio.ImageIO;
  import javax.swing.ImageIcon;

Now lets write show picture code on WindowsOpened evets:
private void formWindowOpened(java.awt.event.WindowEvent evt) { 
   try{
       BufferedImage image1 = ImageIO.read(getClass().getResource("skotechlearn.png"));
       jLabel1.setIcon(new ImageIcon(image1));
   }catch(IOException imgl){}

 }   

How to show external image in jLabel?

If you want to show picture from external url or path, then write code like:
String myimgpath; 
myimgpath= "your exteral file path";
Icon myimgicon = new ImageIcon(myimgpath);
jLabel1.setIcon(myimgicon);

When you run application then it will load picture during runtime and display it on jLabel.

Note:- You can also set jLabel as background image by setting the height width of jLabel according to jFrame.

So, this is the way of displaying image on jFrame in java Netbeans with static and dynamic process which is easily described in above given step by step process in SKOTechlearn post.

Simple Tips to Creating Swing GUI Application in Java

For further learning of coding, programming  or simple tips and trick related to OS, follow SKOTechlearn and learn things as simple as possible.

Tips to Use of jList for Showing Data in Java Swing

Show Drives With Folders and Files in TreeView in VB.Net, C#

If you are trying to show Drives, Folders, Sub-Folders and Files without using FolderBrowserDialog or OpenFileDialog through VB.Net Code. Then you can try TreeView control for this process. To use TreeView as File Explorer or Folder Explorer, there are some simple and easy coding and setting tips you have to apply.

So, here we try to Show Drives with Folders and Files in TreeView in VB.Net, C# coding.

(File's Icons in ListView) Show List of Files with Files' Icons in Listview

But, first we understand why we need TreeView as FileExplorer? The answer is very simple, whenever we develop1 an application and want to show files, folders or drives in static way then we use many controls like ListBox, ListView or TreeView as File browser or Folder browser.

Now, Lets proceed with following point:

  1. Show Drives with Folders and File in TreeView in VB.Net (VB, C#)
  2. Get TreeView Selected Node Path in Label VB.Net (VB, C#)

Now, let's start with point wise.

Searching Files from Folders or Sub-Folders through code using VB.Net

(1). Show Drives with Folders and File in TreeView in VB.Net (VB , C#) :

First we have to add some controls like Button, Label, Treeview. Now here we use these controls with following Names.

ExplorerBtn : Button
MytrView1 : Treeview
MyPathLabel : Label

First, we write code inside Button for calling Drives.

Button’s Click Event for Showing Drives in TreeView.

VB.Net :
 Private Sub ExplorerBtn_Click(sender As Object, e As EventArgs)
  'Clear TreeView
  MytrView1.Nodes.Clear()

  'Loop For Get Drives
  For Each myDrives As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives()
     Dim myDrivesNode As TreeNode = MytrView1.Nodes.Add(mydrives.Name)
     'Adding "Expand" string is use for Add Expand "[+]" option on Drives
     myDrivesNode.Nodes.Add("Expand")
  Next

 End Sub

C# :
 private void ExplorerBtn_Click(object sender, EventArgs e)
 {
    //Clear TreeView
    MytrView1.Nodes.Clear();

    //Loop For Get Drives
    foreach (System.IO.DriveInfo myDrives in System.IO.DriveInfo.GetDrives())
    {
       TreeNode myDrivesNode = MytrView1.Nodes.Add(myDrives.Name);
       //Adding "Expand" string is use for Add Expand "[+]" option on Drives
       myDrivesNode.Nodes.Add("Expand");
    }

  }

So, this code will present output in following way:
Show Drives in Treeview VB.Net
After that, we use 'BeforeExpand' event of Treeview for getting Folders and Files List on particular Drives.

VB.Net :
 Private Sub MytrView1_BeforeExpand(sender As Object, e As TreeViewCancelEventArgs)
   Dim MyExistNode As TreeNode = e.Node
   'Clear TreeNode
   MyExistNode.Nodes.Clear()

   Try
     'Loop For Get Folders
     Dim mypath As String = MyExistNode.FullPath

     'Loop For Get Folders
     For Each myFolders As String In System.IO.Directory.GetDirectories(mypath)
        Dim FldrNode As TreeNode = MyExistNode.Nodes.Add(System.IO.Path.GetFileName(myFolders))
        'Here, Expand is use for add Expanding option "[+]" on folder
        FldrNode.Nodes.Add("Expand")
     Next

     'Loop For Get Files
     For Each MyFiles As String In System.IO.Directory.GetFiles(mypath)
        Dim FLNode As TreeNode = MyExistNode.Nodes.Add(System.IO.Path.GetFileName(MyFiles))
     Next

    Catch ex As Exception

    End Try
  
 End Sub

C# :
private void MytrView1_BeforeExpand(object sender, TreeViewCancelEventArgs e)
  {
     TreeNode MyExistNode = e.Node;
     //Clear TreeNode
     MyExistNode.Nodes.Clear();

     try
      {
        string mypath = MyExistNode.FullPath;

        //Loop For Get Folders
        foreach (string myFolders in System.IO.Directory.GetDirectories(mypath))
        {
           TreeNode FldrNode = MyExistNode.Nodes.Add(System.IO.Path.GetFileName(myFolders));
           //Here, Expand is use for add Expanding option "[+]" on folder
           FldrNode.Nodes.Add("Expand");
         }

        //Loop For Get Files
        foreach (string MyFiles in System.IO.Directory.GetFiles(mypath))
         {
                
            TreeNode FLNode = MyExistNode.Nodes.Add(System.IO.Path.GetFileName(MyFiles));
               
          }

       }
        catch (Exception FlErr)
       {
          MessageBox.Show(FlErr.ToString());
       }

   }

OK, when you run your application this will show following output:
Show Drives Folders Files in Treeview VB.Net

As you can see, when you click on any drive this will expand with containing Folders and files and when you expand any folder this will show your list of sub-folders and files in Treeview.

Styling ProgressBar in VB.Net

(2). Get Treeview Selected Node Path in Label VB.Net (VB, C#) :

Now, let’s try to get selected Node path in Label from Treeview. So, here we go through code process.

You have to first go to “AfterSelect” event of Treeview and write following code:

VB.Net:
 Private Sub MytrView1_AfterSelect(sender As Object, e As TreeViewEventArgs)
    
  Dim MySelectedNode As TreeNode = e.Node
  'Get Selected Node Path
  MyPathLabel.Text = MySelectedNode.FullPath
    
 End Sub

C# :
private void MytrView1_AfterSelect(object sender, TreeViewEventArgs e)
  {
     TreeNode MySelectedNode = e.Node;
     //Get Selected Node Path
     MyPathLabel.Text = MySelectedNode.FullPath;
    
  }

This will work like following way:
Get TreeView Selected Node Path in Label VB.Net

Okay, now we have learned how to Show Drives with Folders and Files in TreeView in VB.Net using VB and C# code. You can also try and ask any question related to this topic describe in SKOTechLearn Tips.

Change jTable Column Header and Rows Color in Java NetBeans Easily

In this post, SKOTechLearn will explain how to Change Color of jTable in Java like Column Header Color, grid Color, Rows Color, Selection Color. When I was started programming in java and using jTable, I faced problem of jTable background color foreground color of particular cells or rows and columns.

So here are the simple and easy tips to Change jTable Column Header and Rows Color in Java Netbeans Easily.

Easily Add Column Header in jTable with Grid Settings in Java

So here SKOTechLearn will described, how to Change jTable Column Header and Rows Color in Java NetBeans in simple way?
jTable background and foreground color in Java

So, Let’s take a look of Following Color changing point.

  1. jTable Column Header Background Color and Foreground or Font Color 
  2. jTable Column Header Background Color and Foreground Color in NetBeans
  3. jTable Rows Background and Foreground Color
  4. Change Background and Foreground Color of Particular Column's Rows in jTable
  5. jTable Selection background and Foreground Color
  6. jTable Selection Background and Foreground Setting in NetBeans

First you have to import Color Class:
 import java.awt.Color;

Now, Let's Proceed with above given point.


 (1). jTable Column Header Background Color and Foreground or Font Color :

There are many ways to change Header’s back color. You can change it through predefined system color or you can use custom color.

Column Header background with default system Color:
 MyTblView.getTableHeader().setBackground(Color.MAGENTA);

Column Header background with Custom Color :
 MyTblView.getTableHeader().setBackground(Color.decode("#696B9E"));

Or you can use JTableHeader class.

Enable or Show jTable Sorting Option in Java

First import this class:
 import javax.swing.table.JTableHeader;

Then use this class with following way:
 JTableHeader TblHeader = MyTblView.getTableHeader();
 TblHeader.setBackground(Color.GREEN);
Same above code process will apply here; we can set Foreground color with system default and custom color setting.

Column Header Foreground with default system Color :
 MyTblView.getTableHeader().setForeground(Color.BLUE);

Column Header Foreground with Custom Color :
 MyTblView.getTableHeader().setForeground(Color.decode("#FCE7FC"));

JTableHeader class for Foreground color code:
JTableHeader TblHeader = MyTbleView.getTableHeader();
 TblHeader.setForeground(Color.RED);

When you run any code the output will show in following way:
jTable_ColumnHeader_Background_and_Foreground_Color_Java


 (2). jTable Column Header Background Color and Foreground Color in NetBeans :

If you are using NetBeans for swing GUI project using jTable, the column header color will apply in different coding way. You have to use DefaultTableCellRenderer class in NetBeans Code.

DefaultTableCellRenderer MyHeaderRender = new DefaultTableCellRenderer();
MyHeaderRender.setBackground(Color.decode("#696B9E"));
MyHeaderRender.setForeground(Color.decode("#FCE7FC"));

MyTblView.getTableHeader().getColumnModel().getColumn(0).setHeaderRenderer(MyHeaderRender);
MyTblView.getTableHeader().getColumnModel().getColumn(1).setHeaderRenderer(MyHeaderRender);
MyTblView.getTableHeader().getColumnModel().getColumn(2).setHeaderRenderer(MyHeaderRender); 

After that this will show given output:
Netbeans_jTable_Header_Color


 (3). jTable Rows Background and Foreground Color :

There is simple code for doing this. But remember one thing; it can change color of all rows. The simple and easy codes are as follows:
 MyTblView.setBackground(Color.LIGHT_GRAY);
 MyTblView.setForeground(Color.BLUE);
This code will not be use for particular rows settings.

This will show the following output.
jTable_Rows_Background_and_ForeGround_Color


 (4). Change Background and Foreground Color of Particular Column's Rows in jTable :

Now, this is the very interesting point, because I have searched this point in many web-page and not find any suitable way to do this.

But, SKOTechLearn will explain simple tips to change Particular Column color of jTable in Java it, write or copy given code and see what happen.

First you have to import DefaultTableCellRenderer class:
import javax.swing.table.DefaultTableCellRenderer;

After that write given code:
 DefaultTableCellRenderer MyCellrendar = new DefaultTableCellRenderer();
 
 MyCellrendar.setBackground(Color.yellow);
 MyCellrendar.setForeground(Color.RED);

 MyTblView.getColumnModel().getColumn(1).setCellRenderer(MyCellrendar);

The output will be display like:
jTable_Particuluar_Column_and_cell_color_java
In getColumn() method, you can put any column number inside it and this will apply on that particular column's rows.

 (5). jTable Selection background and Foreground Color :

In java, there is facility to change selection color of particular rows in jtable according to requirement.

You can apply one line code as described below:
 MyTblView.setSelectionBackground(Color.BLACK);
 MyTblView.setSelectionForeground(Color.YELLOW);

jTable_Selection_Background_Foreground_Color


 (6). jTable Selection Background and Foreground Setting in NetBeans :

If you are using NetBeans, then you can simply go to “Properties” window and find “selectionBackground” and “selectionForeground” option and choose color according to your requirement.

Steps are described in given following image:
jTable_Selection_Color_Setting_Netbeans

So, these are the color changing process which is explained in Change jTable Column Header and Rows Color in Java NetBeans Easily.

Add Column Header in JTable and Grid Line Settings in jTable in Java

When you design you java project and want to show list of data in rows and columns format, you require a table or list, but List only contain one column with multiple rows and table contains multiple columns with multiple rows. You can find complete details of jTable class.

So Friends, here SKOTechLearn will discuss about jTable in Java with details description of Add Column Header in JTable in Java with jTable Grid setting in java NetBeans.

Change jTable's Column Header, Rows, Cell, Selection Color With Simple Steps

Suppose, you want to display some records which contains some Column. Then we have to drag jTable or write code for Adding Column Header in Java with Grid Settigns.


Here we proceed with following way:

  1. Add Column Header in jTable in Java Code
  2. Add Column Header in jTable in Netbeans through Properties
  3. jTable Grid Line Setting in java code
  4. jTable Grid line Setting in java Netbeans through Properties

So, let’s start with point to point.


(1). Add Column Header in jTable in Java Code :

For Column Header in JTable, you have to import some class as describe bellow:
 import javax.swing.JFrame;
 import javax.swing.JScrollPane;
 import javax.swing.JTable;
 import javax.swing.table.DefaultTableModel;

After that simply write following code:
 import javax.swing.JFrame;
 import javax.swing.JScrollPane;
 import javax.swing.JTable;
 import javax.swing.table.DefaultTableModel;

 public class MyTableClass {

   public static void main(String[] args) {
    // TableModel is use for showing rows and columns
    DefaultTableModel MyTablemodel = new DefaultTableModel();
    //Create New Table
    JTable MyTableView = new JTable(MyTablemodel);
    // Add jTable in jScollPane for Showing Column Header
    JScrollPane MyScrollPane= new JScrollPane(MyTableView);
    //Add Column Name 
    MyTablemodel.addColumn("MyColHead_ID");
    MyTablemodel.addColumn("MyColHead_Name");
    MyTablemodel.addColumn("MyColHead_Contact");
    //Add jFrame for showing Table inside frame
    JFrame MyTblFrame = new JFrame();
    MyTblFrame.setTitle("jTable Column Header Frame");
    //Set jFrame Size
    MyTblFrame.setSize(410, 320);
    MyTblFrame.add(MyScrollPane);
    MyTblFrame.setVisible(true);
   }
    
 }

Note : If you want to add rows and columns, DefaultTableModel will provide facility to do this.

When you execute this code this will show the following result:
jTable Column Header in Java


 (2). Add Column Header in jTable in NetBeans through Properties :

If you are using NetBeans for Java, First drag jTable in jFrame after that simply follow the following steps.

1.
 Right Click on jTable control and find “Table Contents…” option.

2.
 Click on “Table Contents…” option. “Customizer Dialog” will be displayed.

3.
 “Customizer Dialog” contains three tabs (Table Model, Columns, Rows ).

4.
 For headers, you have to choose “Columns” tab.

5.
 In “Columns” tab, you will find a table containing “Title, type, Resizable, Editable”. This is use for Column header settings.

6.
 Choose “Columns” tab which is also contain some buttons(Insert, Delete, Move Up, Move Down).

7.
 ‘Insert’ button is used to add Columns, ‘Delete’ is used for delete Columns, ‘Move Up’ and ‘Move Down’ button is used for move column left or right in jTable according to your requirement.

8.
 Select ‘Title’ Column from table and go to “Title” box and write your column Name.

9.
 After that simply close “Customizer Dialog”.

jTable Column Header Settings in Netbeans
Column Header Settings in NetBeans

When all settings will be done, your table will looks like bellow.
jTable Column Header Setting output in Netbeans


 (3). jTable Grid Line Setting in java code :

If you want to change Grid Line color of jTable, first you have to add some rows and then you can write following code which is very simple and one line code.

Grid Color Setting Code:
 MyTableView.setGridColor(Color.red);

Now check it with following code:
public static void main(String[] args) {
    DefaultTableModel MyTablemodel = new DefaultTableModel();
    JTable MyTableView = new JTable(MyTablemodel);
   
    //jTable grid Line Settings
    MyTableView.setGridColor(Color.red);
    
    JScrollPane MyScrollPane= new JScrollPane(MyTableView);
    MyTablemodel.addColumn("MyColHead_ID");
    MyTablemodel.addColumn("MyColHead_Name");
    MyTablemodel.addColumn("MyColHead_Contact");
    // add some rows
    MyTablemodel.addRow(new Object[]{"Col1Row1_0000", "Col2Row1_ABCD", "Col3Row1_XXX0124556"});
    MyTablemodel.addRow(new Object[]{"Col1Row1_0001", "Col2Row1_EFGH", "Col3Row1_XXX01253344"});
    
    JFrame MyTblFrame = new JFrame();
    MyTblFrame.setTitle("jTable Column Header Frame");
    
    MyTblFrame.setSize(410, 250);
    MyTblFrame.add(MyScrollPane);
    MyTblFrame.setVisible(true);
  }

This will display output in given following figure:
jTable Gird Color Change in Java


 (4). jTable Grid Line Setting in java Netbeans through Properties :

If you are using NetBeans for creating Swing project, you will find that jTable has no GridLines. First you have to add Gridlines then you can change Grid color according to your requirement.
 MyTableView.setShowGrid(true);
 MyTableView.setGridColor(Color.MAGENTA);

Or you can simple choose Grid Color from “Properties” window like bellow:
jTable Grid Color Properties in Netbeans

So, In this post you can see, how amazing is to work in java and NetBeans framework. You can simply Add Column Header in JTable and Grid Line Setting in jTable in Java which is detailed explained by SKOTechLearn.