Posts

Data Transfer

Image
Swing supports data transfer through drag and drop, copy-paste, cut-paste etc. Data transfer works between Swing components within an application and between Java and native applications. The ability of data transfer is beneficial to programs between Java applications, between components etc. There are two ways to transfer data. These are: 1. The diagram below displays the Drag and drop (DnD) functionality of Swing. 2. The diagram below displays the cut/copy and paste functionality of Swing. That is the clipboard transfer via cut/copy and paste. The path of the data is shown by the arrows. To be more precise, first of all the bundling of data takes place into a package known as Transferable to begin Data Transfer. Then the data gets extracted by an object i.e. TransferHandler from the Transferable which is provided by the component.

Java 2D API

Programming has become more interactive with Java 2D API. You can add images, figures, animation to your GUI and even pass visual information with the help of Java 2D API. You can easily use 2D within Swing components such as drop shadows since Swing is built on 2D package. Pluggable Look and Feel The Java Swing supports the plugging between the look and feel features. The look and feel that means the dramatically changing in the component like JFrame, JWindow, JDialog etc. for viewing it into the several types of window. You can create your own look and feel using Synth package. There are many of existing look and feels which are available to Swing programs provided by GTK+ look and feel. Moreover, the look and feel of the platform can be specified by the program while running and also to use Java look and feel can be specified by it. The pluggable look and feel indicates that the whole look of the GUI element can be changed i.e. both the visual representation and behavior of a

Java Swing

After learning AWT, lets now see what's Swing? Well, Swing is important to develop Java programs with a graphical user interface (GUI). There are many components which are used for the building of GUI in Swing. The Swing Toolkit consists of many components for the building of GUI. These components are also helpful in providing interactivity to Java applications. Following are components which are included in Swing toolkit: * list controls * buttons * labels * tree controls * table controls All AWT flexible components can be handled by the Java Swing. Swing toolkit contains far more components than the simple component toolkit. It is unique to any other toolkit in the way that it supports integrated internationalization, a highly customizable text package, rich undo support etc. Not only this you can also create your own look and feel using Swing other than the ones that are supported by it. The customized look and feel can be created using Synth which i

Setting an Icon for a Frame in Java

In this section, you will learn how to set an icon for the frame in Java Swing. This program helps us to set the icon (image) on the title bar of the frame. When you open frame or window the icon situated on the title bar is seen on the taskbar also. For this purposes, various methods as follows has been used: frame.setIconImage(Toolkit.getDefaultToolkit().getImage("icon_confused.gif")); Above method sets the icon for the frame or window after getting the image using the Image class method named getImage(). frame.getDefaultToolkit(): This is the method of the Toolkit class which gets the default toolkit. Here is the code of program: import javax.swing.*; import java.awt.*; public class SettingIconFrame{ public static void main(String[] args){ JFrame frame = new JFrame("Setting an Icon for a frame"); frame.setIconImage(Toolkit.getDefaultToolkit().getImage("icon_confused.gif")); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.se

Setting an Icon for a Frame in Java

In this section, you will learn how to set an icon for the frame in Java Swing. This program helps us to set the icon (image) on the title bar of the frame. When you open frame or window the icon situated on the title bar is seen on the taskbar also. For this purposes, various methods as follows has been used: frame.setIconImage(Toolkit.getDefaultToolkit().getImage("icon_confused.gif")); Above method sets the icon for the frame or window after getting the image using the Image class method named getImage(). frame.getDefaultToolkit(): This is the method of the Toolkit class which gets the default toolkit. Here is the code of program: import javax.swing.*; import java.awt.*; public class SettingIconFrame{ public static void main(String[] args){ JFrame frame = new JFrame("Setting an Icon for a frame"); frame.setIconImage(Toolkit.getDefaultToolkit().getImage("icon_confused.gif")); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.se

Draw Pie Chart in Java Swings

This Java Pie Chart example is going to show you how to draw Pie Charts in Java. This Java Pie Chart example is drawing a pie chart to show the percentage of marks obtained in particular session. In this example we have used the object of JFrame class that calls the PieChartPanel class. The Font class represents the font 'Book Antiqua'. The method getPercentInstance() of NumberFormat class returns the percentage format for the current default locale. The ComponenetAdapter class is an abstract adapter class which is called to receive the component events. The BufferedImage class is called by image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB) which defines the image of pie chart The method Math.min(width,height) returns the smaller of two into values. The Ellipse2D.Double class is called to draw the circle shape. Following code draws the leading edge of pie: g2.draw(new Line2D.Double(cp, cq, p, q)) The angle is defined by: phi = (marks[j]/total) * 2 * Math.PI