Scroll bars

In many cases, components of our program interfaces will be too large to display on the screen. This happens most commonly with text fields, which may need to display large sets of text in a limited space. In these situations, we may want to add scroll bars to our components, to allow a user to move the component view to better view content on the…

JComboBox

The JComboBox class is a graphical component that allows you to select an item from a drop-down list. After the selection, only the selected item is displayed. The remaining items are displayed in a pop-up window when the list is opened. Usually, ComboBox elements are strings, but they can be any displayable objects. By default, ComboBox items are uneditable.

The Graphics class

Whenever Java needs to draw something to the screen, it relies on thepaint method. With Swing components such as TextArea, the paint method is called automatically, and we didn’t have to worry about it because we were ok with it drawing the way it is defined by default. When we deal with custom graphics such as circles, we have to start to define the paint method to suit our…

JMenu

Open your text editor or any similar software. You can see that there is a horizontal bar below the title bar with commands such as `file`, `view` etc. We call this horizontal bar the menubar. This bar consists of a set of menus. For example, `file`, `view` are menus in MS Word Software.

Multithreading in Swing

Swing programming is not all about creating windows, labels, and buttons. Creating interfaces is only a part of Swing programmers’ job. These interfaces are just a way for the user to interact with the system. You need to understand here that writing a GUI application is more like writing two applications. You always keep the frontend separate from the background tasks.

Layout managers

Introduction So far we learned many Java Swing components such as buttons, text fields, labels. In a normal window, you can see a lot of these components. One of the main problems that you are going to face when adding elements to a GUI window is how to arrange them. In our previous examples, we arranged them using absolute positioning. That means we gave coordinates for their upper left corner.…

Window listeners

What are window listeners Window listeners are a special type of event listener used to trigger code on events related to the user form displayed on the screen. Some examples of these types of events include closing a window, minimizing a window, or moving a window across the screen.