Learn to develop lightweight, cross-platform desktop applications using Java Swing. Utilize the NetBeans Integrated Development Environment (IDE) to simplify building Graphical User Interfaces (GUI) and screen layouts.
Learn how to build a lightweight cross-platform desktop application with Java Swing using the Netbeans IDE. This course is beneficial to the beginner and seasoned programmer alike. You will learn how to use the powerful Netbeans GUI Builder to quickly develop the user interface with little effort, so you can spend your valuable time building the application logic instead. At the conclusion, you will learn to build a fully functional application interacting with a database. If you prefer to program manually, this course will provide a great entry point into Java Swing's structure and features.
Swing Containers To understand Swing, you need to gain a basic understanding of containers. Containers in Swing are used to group components together. Each container can set a different sort of layout manager for its component. Containers include JFrame, JWindow, JDialog, JPanel, JInternalFrame, and JApplet. Applets are programs designed to be viewed within a web browser. We will not spend time with them, and instead focus on other containers. The containers JFrame, JWindow, JDialog, and JInternalFrame all contain an instance of a class called JRootPane. JRootPane is a container that also contains a component called JLayeredPane, which includes the components JMenuBar and a contentPane. JLayeredPane consists of these layers, allowing components to be overlapped. At the bottom is the Frame_Content_Layer, which contains the JMenuBar and the contentPane. Next, is the Default_Layer where most components are added. Then the Palette_Layer where floating toolbars or palettes can be added. Next, the Modal_Layer or Modal pop-up windows; then the PopUp_Layer for pop-ups and tooltips. Lastly, the Drag_Layer for objects dragged from outside the application. We're only covering the basics of containers here, but it will give you the concepts necessary to understand what we are going to explore. Let's move on and look at each of the containers.
Binding Beans and Data NetBeans offers a powerful tool called the Beans Binding Library that is capable of binding values either between different components or between a component and a database. These values are automatically kept in sync, all requiring only a few lines of code. Let's start with a simple example that binds the properties of two components. One of the components will be the source, and the other will be the target. A good example might be a JSlider providing its value to be displayed in a JLabel. So I've built a new project called BindProject with a class BindGUI containing a JSlider and a JLabel, which I have left with the default names jSlider1 and jLabel1. Let's make the label's font bigger and bold. To bind these, all we have to do is right-click the label, select Bind and the target property we would like to change. Let's choose its text property. The binding source, of course, will be jSlider1, and the value we would expect the slider to output is an integer, so we select the value int. As you see, the label's text has already changed to 0, which is the initial value of the slider. That's all there is to it. Now let's run it, and you see that the label's text is in sync with the output value of the slider.