Thursday, May 14, 2020

SQL Server Connection String with SQL Query in VB.Net

SQL Server Connection String with SQL Query in VB.Net

In VB.Net, if you want to Connect MS SQL Server Database , you have to Import some SQL Connection Class to your application. Now, we proceed with step by step process for MS SQL Server Connection String in VB.Net and the Example of SQL Query in VB.Net.

In this post SKOTechLearn describe the connection of database with SQL Server in two ways in VB.Net.
  1. SqlConnection
  2. OleDbConnection

 1. SqlConnection :
If you connect Database through SqlConnection connection string in VB.Net, you have to import some Namespace.
Assembly Reference Namespace Details
System.Data.SqlClient.dll
System.Data.SqlClient
Connection String and SQL Server Data Provider.
System.Data.dll
System.Data
Provide ADO.Net classes’ access

In Vb.Net, You have to first Import this Namespace:

VB.Net :
 Imports System.Data.SqlClient
 Imports System.Data

C# :
 using System.Data.SqlClient;
 using System.Data;

There are following Syntax of SqlConnection:

VB.Net :
Dim myCnn As SqlConnection
 myCnn  = new SqlConnection ("Data Source = MySQLServer_Name; Initial Catalog = MYDatabase_Name; User ID = My_USERID; Password = My_Password;")

C# :
 SqlConnection MyCnn ;
 MyCnn  = new SqlConnection ("Data Source = MySQLServer_Name; Initial Catalog = MYDatabase_Name; User ID = My_USERID; Password = MySQL_Password;"); 


When you import above given class then write following SqlConnection Connection String example:
VB.Net :
  Dim mySqlConn As SqlConnection
  mySqlConn = New SqlConnection("Data Source = XXX.XXX.XXX.XX; Initial Catalog = MY_ABCD_DB; User ID = sa; Password = XXXXXXXXXXX;")

 try
    mySqlConn.Open()
    MessageBox.Show ( "My Database Connection Successfully Connected" )
    mySqlConn.Close()
 Catch errex As Exception
     MessageBox.Show( "My Database Connection Problem" )
 End Try   


C# :
 SqlConnection mySqlConn;
 mySqlConn = new SqlConnection( "Data Source = XXX.XXX.XXX.XX; Initial Catalog = MY_ABCD_DB; User ID = sa; Password = XXXXXXXXXXXX;");  
            try
            {
                mySqlConn.Open();
                MessageBox.Show ("My Database Connected Successfully.");
                mySqlConn.Close();
            }
            catch (Exception errex)
            {
                MessageBox.Show("My Database Connection Error.");
            } 

ConnectionString Code in VB.Net and C#

 Execute or write Query or SQL Statement in VB.Net through SqlConnection:

Now, Let’s write code to execute query or SQL statement and read data from it.

How to Retrieve Data or Read Data From SQL Server in VB.Net?


VB.Net :
  Dim myDBCnn As SqlConnection
  'SqlCommand is used for write Query Statement
  Dim myDBCmd As SqlCommand
  'SqlDataReader is used for Read data from database
  Dim myDBReader As SqlDataReader

  myDBCnn  = New SqlConnection("Data Source = XXX.XXX.XXX.XX; Initial Catalog = MYDBName; User ID = MYDBUSERID; Password=MYDBPassword;")
  myDBCnn .Open()

  Dim MystrQ As String
  MystrQ  = ""
  'Write Query String
  MystrQ  = "Select * From MyDBTableName;"
  'SQLCommand Syntax: SQLCommand(Query, Connection)
  myDBCmd  = New SqlCommand( MystrQ , myDBCnn )
  myDBReader  = myDBCmd .ExecuteReader
  'Start Loop to read data one by one from Table
      Do  While myDBReader.Read()
          Debug.WriteLine(myDBReader("MyField ").ToString())
      loop
  myDBReader.Close()
  myDBCmd.Dispose()
  myDBCnn.Close()
  MessageBox.Show("Data Reading Process Done.")
  

C# :
SqlConnection mySqlCnn;
  'SqlCommand is used for write Query Statement
  SqlCommand myDBcmd;
  'SqlDataReader is used for Read data from database
  SqlDataReader myDBreader;
  mySqlCnn = new SqlConnection("Data Source = XXX.XXX.XXX.XX; Initial Catalog = MYDBName; User ID = MYDBUSERID; Password = MYDBPassword;");  
            try
            {
                mySqlCnn.Open();
               'SqlCommand Syntax: SqlCommand(Query, Conection)
                myDBcmd = new SqlCommand( "Select * From MyDBTableName;", mySqlCnn );
                'ExecuteReader is used to read data from table
                myDBreader = myDBcmd.ExecuteReader();
               'Start Loop to read data one by one from Table
                while ( myDBreader.Read() ) {
                    Console.WriteLine( myDBreader["MyField"] );
                }
                myDBreader.Close();
                myDBcmd.Dispose();
                mySqlCnn.Close();
                MessageBox.Show( "Query Execution Done" );
            }
            catch (Exception errex)
            {
                MessageBox.Show( "Connection or Query Error " );
            }    
  

 2OleDbConnection :
Now, we proceed with second process to connect MS SQL Server in VB.Net through OleDbConnection.
If you connect through OleDbConnection Connection String in Vb.Net, you have to import some Namespace.
Assembly Reference Namespace Details
System.Data.OleDb.dll
System.Data.OleDb
Provide ConnectionString through data source connection.

First, You will have to import following class:

VB.Net :
 Imports System.Data.OleDb


C# :
 using System.Data.OleDb;


OleDbConnection Connection String Example:

VB.Net :
Dim myOleConn As OleDbConnection
   myOleConn = New OleDbConnection("Provider = SQLOLEDB; Data Source = XXX.XXX.XXX.XX; Database = MyOleDataBase ; Uid = MyUserID; Pwd  style="background-color: #fcfbfb;"= MyServerPassword;")
   try
     myOleConn.Open()
     MessageBox.Show ( "Server Connected Successfully." )
     myOleConn.Close()
   Catch errex As Exception
     MessageBox.Show( "Server Connection Error." )
   End Try


C# :
  OleDbConnection MyOleConn;
  MyOleConn = new OleDbConnection("Provider = SQLOLEDB; Data Source= XXX.XXX.XXX.XX; Database= MyOleDataBase; Uid= MyUserID; Pwd= MyServerPassword;");
             try
            {
                 MyOleConn.Open();
                 MessageBox.Show( "OleConnection Successfully." );
                 MyOleConn.Close();
             }
             catch (Exception olex)
            {
                MessageBox.Show( "OleConnection Error." );
            }

OleDB ConnectionString Code in VB.Net and C#

Note: In OleDbConnection String, you have to add Provider for data source.

Now Let’s come to the Query Example of OleDbConnection.

 SQL Server Execute Query or Write Query through OleDbConnection :

So, there are following way to write query for read data form SQL Server through OleDbConnection.

How to use Select Query in SQL with VB.Net ?

VB.Net :
  Dim myOleConn As OleDbConnection
  'ConnectionString Setting
  myOleConn = New OleDbConnection ( "Provider=SQLOLEDB; Data Source=XXX.XXX.XXX.XX; Database= MyOleDataBase; Uid= MyUserID; Pwd= MyServerPassword;" )  
  Try
      'OleDbCommand for Query
       Dim MyOlecmd As New OleDbCommand( "Select * From MyDBTableName;" )
        MyOlecmd.Connection = myOleConn
        myOleConn.Open()
        'OleDbDataReader to read data from Table
        Dim MyOleReader As OleDbDataReader = MyOlecmd.ExecuteReader()
        'Start Loop until Read data according to Query.
        While MyOleReader.Read()
            'If you want to show Particular field then write code like given bellow.
            Console.Write( MyOleReader("MyField ").ToString() )
        End While
     MessageBox.Show ( "OleDbServer Connected Successfully." )
     'fter that close all connection including OleReader.
     MyOleReader.Close()
     MyOlecmd.Dispose()
     myOleConn.Close()
   Catch oleex As Exception
     MessageBox.Show( "OleDbServer Connection Error." )
   End Try    


C# :
OleDbConnection MyOleConn ;
 OleDbCommand MyOlecmd ;
 OleDbDataReader MyOlereader ;

 MyOleConn = new OleDbConnection( "Provider= SQLOLEDB; Data Source= XXX.XXX.XXX.XX; Database= MyOleDataBase; Uid= MyUserID; Pwd= MyServerPassword;" );
 try
    {
       MyOleConn.Open();
       MyOlecmd = new OleDbCommand( "Select * From MyDBTableName;" , MyOleConn);
       MyOlereader = MyOlecmd.ExecuteReader();
       while ( MyOlereader.Read() )
       {
            Console.WriteLine(MyOlereader["MyField"]);
       }
       MessageBox.Show( "Record Show Successfully." );
       MyOlereader.Close();
       MyOlecmd.Dispose();
       MyOleConn.Close();
    }
    catch (Exception Oleex)
       {
           MessageBox.Show( "Problem in Database Connection. " );
        }

So, SKOTechLearn Described the easiest way where you can use SqlConnection or OleDbConnection class for MS SQL Server Connection String with SQL Query in VB.Net (VB and C# Code).

Saturday, May 9, 2020

If Else Statement in Python with Use of Operators in Python

If Else Statement in Python with Use of Operators in Python

When you write code or programming in any language then, mostly you have to use If Else statement with condition. So, Here SKOTechLearn describes the easy learning way about IF Else Statement in Python.

Basically, If Else statement work on true and false condition.

But, before we start , we understand, how this statement works in python by given following flow chart.

Suppose, If we ask our friend with a cup of Tea, then how will this condition apply?

IF Else statement Flow Chart in Python
If ( <condition> ) :
    <Statement>
else:
    <Statement>

Now, IF Else statement require different types of Operators.

Basically, in condition require “Comparison Operators” and “Logical Operators”.
Comparison Operators in Python :
Name
Details
==
Comparing Equal condition
!=
Comparing Not Equal
>
Comparing Value is Greater Than
<
Comparing Value is Less Than
>=
Comparing Value is Greater or Equal to
<=
Comparing Value is Less or Equal to
<>
Comparing Not Equal

Logical Operators in Python :
Name
Details
and
Statement with Two and more condition, and if all condition are true
or
Statement with Two or more condition, and if any one condition are true
not
Reverse condition if true then false and if false then true

How to Use Operators in Python?


Example of If Else Statement with Comparison Operators in Python:
MyFstVl1 = 135
MySecVl2 = 234

#Condition1
if ( MyFstVl1 == MySecVl2 ):
   print "Condition1 : MyFstVl1 is Equal to MySecVl2"
else:
   print "Condition1 : MyFstVl1 is Not Equal to MySecVl2"


#Condition2
if ( MyFstVl1 != MySecVl2 ):
   print "Condition2 : MyFstVl1 is Not Equal to MySecVl2"
else:
   print "Condition2 : MyFstVl1 is Equal to MySecVl2"


#Condition3
if ( MyFstVl1 <> MySecVl2 ):
   print "Condition3 : MyFstVl1 is Not Equal to MySecVl2"
else:
   print "Condition3 : MyFstVl1 is Equal to MySecVl2"


#Condition4
if ( MyFstVl1 < MySecVl2 ):
   print "Condition4 : MyFstVl1 is Less than MySecVl2"
else:
   print "Condition4 : MyFstVl1 is Greater than MySecVl2"


#Condition5
if ( MyFstVl1 > MySecVl2):
   print "Condition5 : MyFstVl1 is Greater than MySecVl2"
else:
   print "Condition5 : MyFstVl1 is Less than MySecVl2"


#Condition6   
if ( MyFstVl1 <= MySecVl2):
   print "Condition6 : MyFstVl1 is Less than or equal to MySecVl2"
else:
   print "Condition6 : MyFstVl1 is Not Less than or Not equal to MySecVl2"


#Condition7
if ( MyFstVl1 >= MySecVl2):
   print "Condition7 : MyFstVl1 is greater or equal to MySecVl2"
else:
   print "Condition7 : MyFstVl1 is Not greater or Not equal to MySecVl2"


When you compile or run this script, the following output will be display:

 Condition1 : MyFstVl1 is Not Equal to MySecVl2
 Condition2 : MyFstVl1 is Not Equal to MySecVl2
 Condition3 : MyFstVl1 is Not Equal to MySecVl2
 Condition4 : MyFstVl1 is Less than MySecVl2
 Condition5 : MyFstVl1 is Less than MySecVl2
 Condition6 : MyFstVl1 is Less than or equal to MySecVl2
 Condition7 : MyFstVl1 is Not greater or Not equal to MySecVl2
IF Else with Comparision Operator in Python
IF Else Statement Example with Comparision Operator

Example of IF Else Statement with Comparison Operators in Python:
MyStr1 = "python"
MyStr2 = "Learn"
MyStr3 = "Programming"

if ( MyStr1 == "python" and MyStr2 =="Learn" ):
   print " 'And' Operator Output : " + MyStr1 + MyStr2
else:
   print " 'And' Operator Output: String Not Match"
   
if ( MyStr1 == "python" or MyStr1 == "PYTHON" ):
   print " 'Or' Operator Output : " + MyStr1
else:
   print " 'Or' Operator Output : String Not Found"
   
if not ( MyStr3 == "python" or MyStr3 == "PYTHON" ):
   print " 'Not' Operator Output : " + MyStr3 + " is not equal to python"
else:
   print " 'Not' Operator Output : " + MyStr3 + " is equal to python"

The following output will be display, when you run this python code:
 'And' Operator Output : pythonLearn
 'Or' Operator Output : python
 'Not' Operator Output : Programming is not equal to python

IF Else Statement with Logical Operator in Python
IF Else Statement Example with Logical Operator in Python
Nested If Else :
When you want to check condition and want to check another condition after previous condition, then we have to use Nested If Else. Let’s check following example:
 sk = 102
 if (sk < 500): 
    sk = sk % 2
    print ( sk )
    if (sk == 0): 
        print ( "sk is even" ) 
    if (sk > 100): 
        print ( "sk Greater than 100" ) 
    else: 
        print ( "sk Less than 100" )

Output:
 0
 sk is even
 sk Less than 100

If Else ladder (if elif else):
There is following example of Ladder:
 Vl = 35
 if ( Vl == 12 ): 
     print ( "Vl equal to 12" ) 
 elif ( Vl == 18 ): 
     print ( "Vl equal to 18" ) 
 elif ( Vl == 35 ): 
     print ( "Vl equal to 35" ) 
 else: 
     print ( "Vl Not equal to any" )

Output:
 Vl equal to 35

So, Here, SKOTechlearn describe the example of If Else Statement in Python with Logical operator and comparison operators in python.

Friday, May 8, 2020

Remove Multiple Checked Items from Listview in VB6.0 Easy Tips

Remove Multiple Checked Items from Listview in VB6.0 Easy Tips

Whenever you create an application in Visual Basic 6.0, and want to implement your application with data or record through list, then you have to require some component or tool like Listview, FlexGrid, MSHFlexGrid etc. In this control you can add, delete or edit items easily. But in this post, we describe the way where you can remove multiple checked items from Listview in VB6.0 easily with SKOTechLearn.

If you want to proceed only one by one or single item’s removal process, then you can check it from easily edit or delete selected listview items in vb6.0.

But, if you want to remove or delete multiple checked items, then you have to follow the steps describe by SKOTechLearn.

Suppose, this control contain some records and there is a problem to remove of some selected checked item. First you have to implement in Properties of this control like bellow.
ListView CheckBoxes Setting in VB6.0
ListView CheckBoxes Setting
You have to enable “CheckBoxes=True” from Properties windows. Then proceed with following way.

Dynamically add data in ListView with simple way. 


Add some records in loop through code:
Private Sub AddItems_Cmd_Click()
MyListVBox1.ListItems.Clear
'Here MyListVBox1 is Listview Control
Dim i As Integer
i = 1
 While Not i = 10
    MyListVBox1.ListItems.Add , , Right("0000" & i, 4)
    MyListVBox1.ListItems(i).ListSubItems.Add , , "A" & i
    MyListVBox1.ListItems(i).ListSubItems.Add , , Right("0000" & i, 4) & "-" & Val(Replace(Format(Now, "hh:mm:ss"), ":", "")) + i
    i = i + 1
    DoEvents
 Wend
End Sub
Add Items in Listview in Vb6.0
Add some records
Now we select some items for deletion.

Note: If you try to remove data from ascending order like from top to bottom, then it will remove wrong items. You have to proceed from Bottom to top means you have to create a loop which start from bottom to top.

So, we write code for deletion from Bottom to Top Loop. For this process, we drag a button and write code inside it, like bellow.
Private Sub RemoveItems_cmd_Click() 
  Dim rm1 As Integer
  rm1 = MyListVBox1.ListItems.Count
  While rm1 > 0
     If MyListVBox1.ListItems(rm1).Checked = True Then
         MyListVBox1.ListItems.Remove (rm1)
     End If
     rm1 = rm1 - 1
     DoEvents
  Wend
  MsgBox "Checked Items Deleted Or Removed Successfully.", vbInformation
End Sub
Remove Checked Items From Listview in VB6.0
Remove Checked Items
When you write code inside “RemoveItems_cmd” and run application,  and press this button. The checked record will be deleted like above image.

Get ListView selected row data in TextBox.


If you want to store deleted item or show it on another ListViewBox then, just add this control on application and write the following code for it.
Private Sub RemoveItems_cmd_Click()
 MyListVBox2.ListItems.Clear
 Dim rm1, ls2 As Integer
 ls2 = 1
 rm1 = MyListVBox.ListItems.Count
 While rm1 > 0
    If MyListVBox.ListItems(rm1).Checked = True Then
      'add checked item in another listview control
      MyListVBox2.ListItems.Add , , MyVListBox.ListItems(rm1).Text
      MyListVBox2.ListItems(ls2).ListSubItems.Add , , MyListVBox.ListItems(rm1).SubItems(1)
      MyListVBox2.ListItems(ls2).ListSubItems.Add , , MyListVBox.ListItems(rm1).SubItems(2)

      MyListVBox1.ListItems.Remove (rm1)

      ls2 = ls2 + 1
   End If
   rm1 = rm1 - 1
   DoEvents
 Wend
 MsgBox "Checked Items Deleted Or Removed Successfully.", vbInformation
End Sub
Suppose my second Listview is “MyListVBox2” then we first add checked item after that we remove that particular items like above code and you will see the output will be just like bellow image.
Get Deleted Items in Other ListView in VB6.0
Get Deleted record in Other ListView
You can easily Get checked record in other List Control.

So, This is the way for Removing or Delete Multiple Checked Items From ListView in VB6.0 with SKOTechLearn.

Friday, April 10, 2020

How to jRadioButton Select One Option at a Time in Java Netbeans

How to jRadioButton Select One Option at a Time in Java Netbeans

Whenever you use multiple jRadioButton in java, you have to face problem that it can not work as jRadioButton select one option at a time in java when you click on that particular option.

When you select one option and then jump or select other option, then previous option also selected including current selected option. So, get rid of this problem, you have to try or use following two ways according to SKOTechLearn Tips.
  1. jRadioButton Select One Option at a Time in Java through ‘ItemStateChanged’ events 
  2. Use ButtonGroup for Select One Option at a Time in Java
So, before we start, We have to drag this control , then change its Name and Text according to your self.

 1. jRadioButton select One Option at a time in java through ‘ItemStateChanged’ events:
Suppose we drag 3 jRadioButton with name MyOption1, MyOption2, MyOption3. So, we have to write code inside every RadioButton’s ‘ItemStateChanged’ events.

jRadioButton ‘ItemStateChanged’ events


If MyOption1 is selected then write following code:
 private void MyOption1ItemStateChanged(java.awt.event.ItemEvent evt) { 
        if (MyOption1.isSelected()){
            MyOption2.setSelected(false);
            MyOption3.setSelected(false);
        }
    }

If MyOption2 is selected then write following code:
 private void MyOption2ItemStateChanged(java.awt.event.ItemEvent evt) { 
        if (MyOption2.isSelected()){
            MyOption1.setSelected(false);
            MyOption3.setSelected(false);
        }
    }

If MyOption3 is selected then write following code:
 private void MyOption3ItemStateChanged(java.awt.event.ItemEvent evt) { 
        if (MyOption3.isSelected()){
            MyOption1.setSelected(false);
            MyOption2.setSelected(false);
        }
    }
jRadioButton ItemStateChanged Event in java
ItemStateChanged Event

As you can see that when write this code and run application. And when you select any option, others will be deselected.

 SetSelected(true) : Is Use For Selection
 SetSelected(false) : Is Use For Deselecting

 2. Use ButtonGroup for Select One Option at a Time in Java:
Now, first we talk about ButtonGroup, Basically ButtonGroup class is use for selecting only one RadioButton and deselects remain RadioButton.

So, this can be done by adding all related jRadioButton in ButtonGroup.

Now, drag ButtonGroup on jFrame. Then write following code inside your jFrame class or ‘formWindowOpened’ events.

Import ButtonGroup class


First, you have to Import ButtonGroup class:
  import javax.swing.ButtonGroup;


Add jRadioButton on ButtonGroup Class


If you want initialize in jFrame class then write code like following:
public MyRadioButtonFrame() {
        initComponents();
        ButtonGroup MyOptiongroup = new ButtonGroup();
        MyOptiongroup.add(MyOption1);
        MyOptiongroup.add(MyOption2);
        MyOptiongroup.add(MyOption3); 
    }

Or you can initialize it in jFrame’s ‘formWindowOpened’ events like bellow:
public formWindowOpened(java.awt.event.WindowEvent evt) {
        ButtonGroup MyOptiongroup = new ButtonGroup();
        MyOptiongroup.add(MyOption1);
        MyOptiongroup.add(MyOption2);
        MyOptiongroup.add(MyOption3); 
    }

jRadioButton With Example


If you want to display selected radiobutton text on jLabel then go to following examples.
private void MyOption1ItemStateChanged(java.awt.event.ItemEvent evt) {
        if(MyOption1.isSelected()){
            MyLabel1.setText("MyOption1 is Selected");
        }
    }

private void MyOption2ItemStateChanged(java.awt.event.ItemEvent evt) {
        if(MyOption2.isSelected()){
            MyLabel1.setText("MyOption2 is Selected");
        }
    }

private void MyOption3ItemStateChanged(java.awt.event.ItemEvent evt) {
        if(MyOption3.isSelected()){
            MyLabel1.setText("MyOption3 is Selected");
        }
    }
jRadioButton Option Select Example in Java
RadioButton Option Select Example

These two point will be use as jRadioButton Select one Option at a time in java Netbeans with SKOTechLearn Tips.

Monday, April 6, 2020

Use jTextField in java Netbeans with Properties and easy example

Use jTextField in java Netbeans with Properties and easy example

In java, when you want to input some text or value etc., you have to choose some palette. So, here SKOTechlearn describe about jTextFiled in java Swing Netbeans with some basic properties settings and some easy example.

Java Swing Gui Project in Netbeans


So, what point we cover in this post according to jTextField palette which is described bellow:
  1. jTextField Properties Settings in Netbeans
  2. jTextField Properties setting through code
  3. jTextFileld with Get and set Value Example
So, Lets start, First drag this control on jFrame , then proceed with above steps.

 1. jTextField some basic Properties Settings in Netbeans:

Properties
Details
editable
This property is used for lock or unlock TextField
background
You can choose Backcolor
foreground
You can choose text color
Font
Change Font with Font Name, Font Style and Font Size
horizontalAlignment
Set Text alignment (LEFT, RIGHT, CENTER, LEADING, TRAILING)
SelectedTextColor
Set Border like (Bevel Border, Empty Border, Line Border etc)
Font
Change selected text Forecolor from this properties
SelectionColor
Change text selection back color
Now, understand it with following figure.
jTextField Properties Settings in java
Properties Settings in java Netbeans
So, this way you can easily change some basic properties of jTextField in java Netbeans.

 2. jTextField Properties Setting Through Code:
Now, you can apply above given properties settings through following code.

 a). Lock or Unlock JTextField:
The following code is for unlock or make editable TextBox.
private void TxtPropertyBtnActionPerformed(java.awt.event.ActionEvent evt) {                                               
     
   MyInputTxt.setEditable(true);

    }  
The following code is for lock or disable edit in TextBox.
private void TxtPropertyBtnActionPerformed(java.awt.event.ActionEvent evt) {                                               
     
   MyInputTxt.setEditable(false);

    }  

 b) Change Background Color of jTextField :
First Import color class for background and foreground color:
import java.awt.Color;
Then write following code.
private void TxtBackColorBtnActionPerformed(java.awt.event.ActionEvent evt) {                                               
   
   MyInputTxt.setBackground(Color.yellow);
      //or 
    // For Custom Color        
   MyInputTxt.setBackground(new Color(246,220,220));    
 
    }  

 c) Change Text Color or Foreground Color of JTextField:
private void TxtForeColorBtnActionPerformed(java.awt.event.ActionEvent evt) {                                               
   
   MyInputTxt. setForeground (Color.GREEN);
   //or 
   // For Custom Color        
   MyInputTxt. setForeground (new Color(146,220,120)); 
    
    }

 d) Change Font for jTextField:
Fist Import Font class on your project like bellow.
import java.awt.Font;
Then write following code.
private void TxtFontBtnActionPerformed(java.awt.event.ActionEvent evt) {                                               

        Font myFont = new Font("Calibri",Font.BOLD,20);
        MyInputTxt.setFont(myFont);  
 
    }

 e) Set Horizontal Alignment:
Import following class.
import javax.swing.JTextField;
After that write following code.
private void TxtHAlignBtnActionPerformed(java.awt.event.ActionEvent evt) {   

     MyInputTxt.setHorizontalAlignment(JTextField.CENTER);

}

 f) Change border style of jTextField:
First import border class.
import javax.swing.border.Border;
Then write following code:
private void TxtBorderBtnActionPerformed(java.awt.event.ActionEvent evt) {                                               
       
    Border myborder = BorderFactory.createEtchedBorder(0,Color.cyan, Color.yellow);
    MyInputTxt.setBorder(myborder);

    }

 g) Selected Text Color and Selection Color :
    // For Seleted Text Color
        MyInputTxt.setSelectedTextColor(Color. gray);
  // for Selection Color
         MyInputTxt.setSelectionColor(Color. ORANGE);

 3. jTextFileld with Get and Set Text Example:
In this process we consider about how to change value of jTextField or retrieve value from one TextField to another in java Swing Netbeans.

jLabel Design in Java Netbeans


So, the following code example will explain all these.

In Java For Input value we use setText(String) and for retrieve value or text we use getText().

 Code For Input or Set Text:
private void SetTxtBtnActionPerformed(java.awt.event.ActionEvent evt) {                                          
      
        MyInputTxt1.setText("SKO Tech Learn Tips");
        
    }

 Code for get text from one jTextField and set to another:
private void GetTxtBtnActionPerformed(java.awt.event.ActionEvent evt) {                                          
    String myStr;
    myStr = MyInputTxt1.getText();
        MyInputTxt2.setText(myStr);
    }
GetText and SetText in Java
GetText and SetText Code in Java

Auto Resize Palette or controls in java


So this is the some basic properties settings in jTextField and use of jTextField in java Netbeans.

Open othe jframe through button click in java