Monday, July 15, 2019

Connect Sql Server Database in Netbeans with sqljdbc Driver

Connect Sql Server Database in Netbeans with sqljdbc Driver


In Netbeans, there is facility to connect any type of database through server or locally. But there is point that, you have to use particular driver for it. Suppose, if you want to View database and related tables on your system, and want to implement or create database or tables in related SQL server, So, it provides the easy way of performing these kinds of things.

So, In this post we will learn, how to connect MS SQL server database in Netbeans with sqljdbc driver with SKOTechLearn Tips.

First remember one thing; you need a driver for it. And this name is sqljdbc4.jar or maybe you find latest version of it. There is many downloading site available there, you can download from here.

After downloading this file. Follow the steps Bellow.

 How to connect sqljdbc driver with Netbeans?

For it, just follow the step by step process as given follows:

  1. Open this application and there are three tabs with name “Projects”, “Files” and “Services”. Go to “Services” tab in Left side of screen.
  2. After that the “Services” tab containing the tree list like “Databases”, “Web Services”, “Servers” etc.
  3. Go to “Databases” Option. And Expand it through the plus sign .
  4. This will also show you sub tree list with options “Java DB”, “Drivers” etc.
  5. Right click on “Drivers” option and select “New Driver…” option from drop down menu.
  6. New JDBC Driver” screen will show. Find “Add..” button and click on it.
  7. A “Select Driver” screen will appear. Just go to path where the sqljdbc is exists. And select it and Press “Open” button.
  8. After that press “OK” button from “New JDBC Driver” screen.
Just figure out following image.
sqljdbc driver with Netbeans
Driver process in Netbeans
Now the SQL server driver will be connected to Netbeans Database services.

 How to connect SQL Server with Netbeans?

After completion of above process, now it’s time for database connectivity from server. So First you have to again go to “Services” tab and proceed in following process.
  1. Again go to “Databases” option from Tree list and right click on it.
  2. Right click and select “New Connection…” option.
  3. A “New Connection Wizard” window will appear.
  4. Here find “Driver” combo box and select your created connection here. Then press “Next” Button.
  5. This will proceed in “Customize Connection” screen.
  6. Here fill up Field with following way.
Host:xxx.xxx.xx.xx
Port:xxxx
Database:SKOTechLearn (Whatever your database name)
Instance Name:
User Name:SA (or anything which you have defined)
Password:***********
7. Now, Press on “Test Connection” button. If Test Connection Success, then press on “Next” button.
8. Next Screen will be for “Choose Database Schema”. Here, select schema like “dbo”.
9. After that “Choose name for connection” screen will show, input your desire name and then click on “Finish” button.
SQL Server Connection Process in Netbeans
SQL Server Connection Process
As you can see the related database connection has been established with input connection name eg. “MYDB_SKOTechLearn”. Now when you expand it, it will show “SKOTechLearn” Database and inside this, there is table details you find there. Now you can easily create your table inside it.

So, Here SKOTechLearn Tips describe the way, where you can connect sql server database in Netbeans with sqljdbc driver.

Saturday, June 29, 2019

jOptionPane Messages Types with image in java NetBeans

jOptionPane Messages Types with image in java NetBeans

In java, if you want to show message box, you have to use jOptionPane class to handle message dialog box. If you know, how to show Message box in vb or vb.net. Then you will not face any problem in java, basically every programming language contains some same things in coding.

So, in this post SKOTechLearn will describe the process of showing jOptionPane Messages Types with image in java NetBeans.

What is jOptionPane in Java?

It is simply a message box in which you can define a message and show in different types as we learn in this post.

There is following types of Msg dialog appearance that we will learn:
 (1). Show simple Plain MsgBox
 (2). Msgbox with Custom image icon dialog
 (3). MsgBox in Yes/No option with image dialog
 (4). Error MsgBox dialog
 (5). Information MsgBox dialog

So, let's find step by step every message process.

Now first we learn how to show simple MsgBox dialog.
First, we drag some jButton for every MsgBox. And will write code for it.

 (1). Show simple jOptionPane Msg dialog :

For showing this dialog, you have to simply import its class. Then call it in any component or run time process.
import javax.swing.JOptionPane;

If there is only simple Msg dialog requirement, this is called plain MsgBox. We want to show it through butons’s click activity. So, type following code as we written.

private void MsgBtnActionPerformed(java.awt.event.ActionEvent evt) {   
       JOptionPane.showMessageDialog(null, "Basic Plain Msg", "Plain MsgBox", JOptionPane.PLAIN_MESSAGE);
         }

When you run it, it will show the following output.
Plain Message box in Netbeans
Plain Msg dialogbox

 (2). jOptionPane with Custom image icon dialog :

Suppose you have an image icon, which you want to show with containing message box, which indicate your application process. Then create an image icon and save it as .png or .jpg format and drag it to your package.

Suppose we have a file with name "msgicon.png" Message Icon in java . Then write code like:

private void ImgMsgBtnActionPerformed(java.awt.event.ActionEvent evt) {                                          
  try{
        BufferedImage imageicn1 = ImageIO.read(getClass().getResource("msgicon.png"));
        ImageIcon iconsk = new ImageIcon(imageicn1);
        JOptionPane.showConfirmDialog(null, "Custome Image Base Msg", "Msg with Image icon",
        JOptionPane.PLAIN_MESSAGE, 3, iconsk);
  }catch(Exception msex1){}
    }

After that this code will present a custom icon base msg.
Custom Image base Message box in Netbeans
Custom Image Base Msg DialogBox

 (3). jOptionPane with Yes No option with image dialog :

For saving or editing or some other action you need a MsgBox that show Yes/No option for that process. You have to add if else statement for it.

For clear description we add some jLabel and will see the output of Yes/No button press, which show in jLabel.

For more understanding purpose, just look at following code:

private void YesNoMsgBtnActionPerformed(java.awt.event.ActionEvent evt) {                                            
try{
    
   BufferedImage imageicn1 = ImageIO.read(getClass().getResource("msgicon.png"));
        ImageIcon iconsk = new ImageIcon(imageicn1);
  //Condition if you press “Yess” Button.
          if (JOptionPane.showConfirmDialog(null, "Sure for this process", "Ye No Option",
            JOptionPane.YES_NO_OPTION,3, iconsk) == JOptionPane.YES_OPTION) {
           jLabel2.setText("Yes");
           jLabel2.setForeground(Color.blue);
   } 
    //Otherwise if you press “No” Button.
     else {
       jLabel2.setText("No");
       jLabel2.setForeground(Color.red);
    }
 
  }catch(Exception msgl){} 
    }

And run-time this will show like:
YesNoOption Msg Box in Netbeans
Yes/No Msg Dialog
As you can see when pressing on “Yes” button, the result is showing in jLabel2 as “Yes” and pressing on “No” button, the result is showing in jLabel2 as “No”.

 (4). jOptionPane with error dialog :

If you want to show an error Msgbox, there is simple code for it.

private void ErrMsgBtnActionPerformed(java.awt.event.ActionEvent evt) {                                          
JOptionPane.showMessageDialog(null, "Sorry Activity Fail", "Activity Fail Error", JOptionPane.ERROR_MESSAGE);
    }
Error Msg dialog in Netbeans
Error Dialog Box

 (5). jOptionPane with information dialog :

For successful saving, editing, deleting and listing information, you need to show the information MsgBox. Just change some code inside error dialog. And the Msg dialog will be change in information dialog.

private void InfoMsgBtnActionPerformed(java.awt.event.ActionEvent evt) {                                           
JOptionPane.showMessageDialog(null, "Successfully Done Activity", "Activity Done Information", JOptionPane.INFORMATION_MESSAGE);
    }

information Message box in java
Information Dialog Box
So, there is some jOptionPane Messages Types with image in java NetBeans as described above with step by step process, just do same as SKOTechLearn Tips mention above.

Thursday, June 20, 2019

Change Look of jRadioButton through Image in java Netbeans

Change Look of jRadioButton through Image in java Netbeans

In this article SKOTechLearn Tips will show you the features of jradiobutton, In java you can design your controls or swing controls according to your need. We will learn how to change different types of look of jradiobutton through image in java Netbeans.
Different look of jRadiobutton
jRadioButton's Looks

 Default RadioButton to Graphical RadioButton:

First of all you have to create some image just look like radio button. For designing it, you can use Powerpoint or googling image and modify according to you desire look.

Or you can save following:

OptionButton’s icon category 1: JOption1 for set icon  JOption1 icon for focus  JOption1 icon for select

OptionButton’s icon category 2: JOption2 for set icon  JOption2 icon for focus  JOption2 icon for select

OptionButton’s icon category 3: JOption3 for set icon  JOption3 icon for focus  JOption3 icon for select


These above images are in PNG format with transparent background, you can right click and save it and use it on your project.

After designing and creating image, just go to your Project’s Package and copy all images and paste it on package.
copy files in java package process
Copy Files in java package
When you will copy it,  come to following points.

 Add image for front view:
Now go to you jRadioButton’s Properties screen.
Find “icon” option and select your desire image.

 Add image for Focus:
In Properties screen, find “rolloverIcon” option.
And select focus icon from here.

It will change during focus on control.

 Now last, add icon when you select it:
Just same find option “selectedIcon”. And add picture you have created.

The following picture defines all steps.
Set image icon in jradiobutton
Different types of icons selection Process
So, this way you can easily change look and feel of jRadioButton in java.

 How to change look of jRadioButton through code in java? 

If you want to proceed through coding during runtime change process, here is the following way.
Define all icon in Application’s initComponents events.

public JRadioButton_Look() { 
        initComponents();
        try{
       // Here MyOptionBtn1 is jRadioButton.
        BufferedImage imgico = ImageIO.read(getClass().getResource("JBtn1.png"));
        MyOptionBtn1.setIcon(new ImageIcon(imgico));
        
         BufferedImage imgicofocus = ImageIO.read(getClass().getResource("JBtn1_Focus.png"));
        MyOptionBtn1.setRolloverIcon(new ImageIcon(imgicofocus));
        // setRolloverIcon is for when your cursor move on it or focus on it.
        
         BufferedImage imgicoselect = ImageIO.read(getClass().getResource("JBtn1_select.png"));
        MyOptionBtn1.setSelectedIcon(new ImageIcon(imgicoselect));
         // setSelectedIcon is for when you select this option.

        }catch(Exception ex1){}
       
        }

There is another long way through code where you have to write code in control’s FocusGained, FocusLost, MouseMoved, ItemStateChanged events. After that you will find same look wise process in it.

 How to transparent background of jRadioButton? 

When you drag jRadioButton, it will present in background default color after changing the icon it will contain the background default color as shown bellow.
Default background color of RadioButton
Default background color
So, the point is that how to transparent it?

The solution is that you have to unchecked the “opaque” option from “Properties” screen. And the magic will present. The background color will be invisible just same as define following.
Transparent background of RadioButton
Transparent background Process
So, you can understand easily that in Java, you can change look of jRadioButton through image with SKOTechLearn Tips.

Thursday, June 13, 2019

Open edit cdr file and convert cdr to jpg in windows

Open edit cdr file and convert cdr to jpg in windows

If you have problem of opening cdr (coreldraw) files in windows. So, don’t worry about it, in this post SKOTechLearn will tell you the easy way of opening cdr in windows without installing coreldraw. And also describe a free open source tool that can be use for editing or converting it to jpg or png in windows.

So, Let’s learn how to open edit cdr file and convert it to jpg in windows.

 How to Open cdr file?

First of all, you have to know that cdr is a vector image format, which cannot open easily on any other image viewer tools like “Microsoft Office Picture Manager” or “Windows Photo Viewer”. You have to use a particular tool that will support Vector image like “CorelDraw” or “Inkscape”.
You can use “Inkscape” for it. It is lightweight and free with open source tool.

First, you have to download “Inkscape” for windows. There is option of OS compatible for Windows, Linux with (32bit, 64bit) architecture. Just go to site and follow the steps.
Download_Inkscape_instruction_For_Windows
"Inkscape" Download Instruction
I recommend for “Windows Installer Package (.msi)” option for download. Now after downloading and Installing “Inkscape”, if you want to open your file in this application or set “Inkscape” as default application for opening it. For this default process procedure follow the image bellow.
Set as default application process in windows
Set as default application process
As you can see, we First right click on it.

Then selected “Open” option. This will show “Windows” screen.

In this screen, we selected “Select a program from a list of installed program” option. And pressed “OK” button.

it has again presented another screen of “Open with”. If this screen not show “Inkscape” application, press on “Browse” button.

Now in “Open with…” screen go to “C:\Program Files\Inkscape” and select “Inkscape.exe”.

After this process. Your default icon will looks like above given image.

And the file will show in this application like bellow.
Open_cdr_in_Inkscape
Open Inkscape

 How to edit cdr file?

For editing it, you can easily select , move, resize, delete and insert object of this vector image.
Everything available for editing in this tool.
Edit_Vector_Image_in_Inkscape
Edit Vector Image process
 Note: You can easily open it in “Inkscape” and easily edit or modify it but, you cannot save it in cdr extension. You can save it as “*.svg” extension or other format.

 How to convert cdr to jpg or other format?

If you want to convert it in JPG, First remember one thing, you have to fist convert it in PNG format because there is no option in direct JPG conversion. Now, you have to proceed in following way:

 Convert through “Save As..”:
  • Go to “File” menu and Find “Save As…” .
  • If you select “Save As…”option, “Select File to save to” screen will appear.
  • Find “Save as type:” combo and it will show different types of file format.
  • Find “Cairo PNG (*.png)” and save it in desire location.
 Convert through “Export PNG Image…”:
  • Go to “File” menu and Find “Export PNG Image…
  • It will present right side pane. Just Input path and File name in “Filename” Textbox.
  • And then press “Export” button.
cdr_to_Image_convert_Process
CDR to PNG convert Process
Now it will be converted in PNG format.

After that open PNG file in MS Paint and save it as JPG format.

Through "Inkscape" you can easily convert it in different format, there is the following conversion exist in this tools:

  • Cdr to PDF
  • Cdr to  PS (Post Script)
  • Cdr to dxf (AutoCAD DXF R14).....etc.

So, Here is the way where SKOTechLearn described, how to open and edit cdr file and convert cdr to jpg in windows.

Tuesday, May 28, 2019

Design and Show data or items in jList in java Netbeans

Design and Show data or items in jList in java Netbeans

In java, jList basically is use for showing items according to requirement. It can display items, data or files static or dynamic way. So, here SKOTechLearn will describe step by step procedure of how to design and show data or items in jList in Java Netbeans.

But we first start with design process of this component. In this process we proceed in following way:

 (1) How to Change background and selection color in jList ?
 (2) How to Change the Selection mode in jList ?
 (3) How to Show data or items in jList in design time ?
 (4) How to Show data or items in jList Dynamically ?
 (5) How to Show items details in Horizontal or Vertical Scrolling way ?

Now let’s start.

jOptionPane with Different type of Message Types

 (1) How to Change background and Selection color in jList ?

First drag this control to jFrame and go to Properties window and find “background”, “foreground”, “selectionBackground” and “selectionForeground” option. Then change color according to your desire.
  • background: this will change the control’s back color.
  • foreground: this will change font color.
  • selectionBackground: this will change the color of selected item’s back color.
  • selectionForeground: this will change the font color of selected item.
Color_Settings_of_jList_in_Java
Color Settings of List in Java
If you don’t want to change it through properties, you can write code as mention bellow:

public MyJframe() {
        initComponents();
        MyLst1.setBackground(new Color(204,255,204));
        MyLst1.setForeground(new Color(204,0,51));
        MyLst1.setSelectionBackground(new Color(255,204,204));
        MyLst1.setSelectionForeground(new Color(0,0,255));
    }

 (2) How to Change the Selection mode in jList ?

Just go to “Properties” and find “selectionmode” option. If you want select one item at a time that means you are using Single selection mode or want to select multiple content then it is in “MULTIPLE_INTERVAL” mode. This properties option will help according to requirement.
  • For Single item selection, just select “SINGLE”.
  • For multiple selection, just select “MULTIPLE_INTERVAL”.
Selectionmode_of_jList_in_Java
Selection mode Setting

 (3) How to show data or items in jList in design time ?

If you want to add data in static way in design time, you can use Properties window or you can define all in “formWindowOpened” event. First we add data through Properties window:

jRadioButton with different Style and look

Just find “model” option and click on “Custom editor” button like bellow.
add_data_in_list_in_java
Add Data Process
As you can see a “model” screen will appear, just press “Enter” key and input your item name. Then press “OK” button. Now it will be add on list.

Now come to code with static way in application’s opened event.
private void formWindowOpened(java.awt.event.WindowEvent evt) {                                  
        DefaultListModel MyLstModel = new DefaultListModel();
                    MyLstModel.addElement("MyFirstdata_1");
                    MyLstModel.addElement("MySecondtdata_2");
                    MyLstModel.addElement("MyThirddata_3");
                    MyLstModel.addElement("MyForthdata_4");
                    MyLstModel.addElement("MyFifthdata_5");
        MyLst1.setModel(MyLstModel);
    }  

When you run application, it will present you the following output.
Static_Way_To_Show_Data_in_JList
Static Way of displaying Data

 (4) How to Show data or items in jList Dynamically ?

If we consider about displaying details in list by button’s press. And want to display loop wise content, then we will say it as dynamic in run time process.

Suppose we have record approx 1 to 100 or more and want to display in list through loop. Then we write following code in jButton’s “ActionPerformed” event.

private void Show_BtnActionPerformed(java.awt.event.ActionEvent evt) {                                         
 DefaultListModel MyLstModel = new DefaultListModel();
        for (int ls = 0; ls < 101; ls++) {

                    MyLstModel.addElement("SK_"+ ls);

        }
        MyLst1.setModel(MyLstModel);
    } 

And when you press “Show Items” button the following output will appear.
Dynamic_way_to_Show_Data_in_jList
Dynamic way to displaying Data

 (5) How to Show items details in Horizontal or Vertical Scrolling way ?

Now come to the last point. Here, you can easily show list details in HORIZONTAL or VERTICAL. You will find an option of “layoutOrientation” it contain three options:

  1. VERTICAL_WRAP
  2. VERTICAL
  3. HORIZONTAL_WRAP

Just select any option and see what will happen at runtime. The details will define bellow.
Orientation_of_List_Details_in_Java
Orientation of List Details
This way you can change the orientation of Details as describe in above image.

Find complete details of jList.

So, there is some features and properties of List, by which you can easily display items in java application, Just follow the steps and learn How to Design and Show data in jList in java Netbeans with SKOTechLearn Tips.