Skip to main content

Posts

Java List

Java List The object of JList class represents a list of text items. The list of text items can be set up so that the user can choose either one item or multiple items. It inherits JComponent class. Lists can have many items, so they are often put in  scrolls panes. Jlist is always associate with INDEXing . the first item you add will have index 0, second item having index 1, third item will having index 2 and so on. How to Create List  Just Drag and Drop jlist from palette. How to add item in List Use model property from property window , as I already mentioned in combo box section. Another way  to add tem in List is by using Default model. hear I am going to show you an  example for this; import javax.swing.DefaultListModel; import javax.swing.JList; public class Main {   public static void main(String[] argv) throws Exception {     DefaultListModel model = new DefaultListModel();    ...

Java Combo Boxes

Java Combo Boxes Create a new project for this (Java > Application). Call the project   formcontrols , and uncheck the "Create main class" box: Click the Finish button on the wizard to create the project. Now add a form by right-clicking the project name in Projects window and selecting   New > JFrame Form : When the dialogue box appears, enter   FormObjects   as the Class name, and   form_controls_lesson   as the package name: You will then have a Class called FormObjects, which is in the package called form_controls_lesson, which in the formcontrols project. You will also have a new form on which to add controls. The JComboBox Control A combo box is a drop down list of items that can be selected by a user. It can be found in the NetBeans palette, under Swing Controls: Locate the Combo Box control and drag one on to your form. Drag a Button onto the form, and a Text Field. What we'll do is to place the item selected ...

Java Check Boxes

Java Check Boxes A check box is a way to allow your users to select and deselect items. They can be a little fiddly, though, so it's a good idea to add them to a panel. That way, you can move them all at once just by moving the panel. So add a panel to your form, which can be found under Swing Containers in the NetBeans palette. Now locate the check box control. Drag a check box onto your panel. The text   jCheckBox1   is the default text. You can change this either in the properties window, or by right-clicking the check box. From the menu that appears, select Edit Text (we've chopped a few menu items off the list, in the image below): When you click on   Edit Text , the default text will be highlighted: Type   C Sharp   over the top of the highlighted text: Press the enter key on your keyboard to confirm the change. The text will change for your check box: However, this just changes the text, and not the variable name. The variab...

Java Radio Buttons

Java Radio Buttons The JRadioButton class is used to create a radio button. It is used to choose one option from multiple options. It is widely used in exam systems or quiz. It should be added in ButtonGroup to select one radio button only. Let's see how they work. Drag and drop a panel onto your form. Then locate the Radio Button control in the NetBeans palette. Drag a Radio button onto your new palette. It should look like this: The default text for the first radio button is   jRadioButton1 . We'll use our radio buttons to allow a user to select a payment method. So change the text of your radio button to   Credit Card . (The text can be changed in the same way as you did for check boxes. Again, we'll leave the variable name on the default of   jRadioButton1 .) Add two more radio buttons to the panel. Change the text to Debit Card, and PayPal: There is, however, a problem with the radio buttons you've just added. To see what the problem is, ru...

Password Field

Password Field JPasswordField is a subclass of the JTextField so it acts like an ordinary text field but it hides the actual characters typed by showing a series of echo characters such as asterisks (*) or a dots, for security purpose . For exampe:          An example for  Login Form :-  

Learning Swing with the NetBeans IDE

Learning Swing with the NetBeans IDE NetBeans IDE Basics It is not necessary to learn every feature of the NetBeans IDE before exploring its GUI creation capabilities. In fact, the only features that you really need to understand are the Palette, the Design Area, the Property Editor, and the Inspector. We will discuss these features below. The Palette                              The Palette contains all of the components offered by the Swing API. You can probably already guess what many of these components are for, even if this is your first time using them (JLabel is a text label, JList is a drop-down list, etc.) From this list, our application will use only JLabel (a basic text label), JTextField (for the user to enter the temperature), and JButton (to ...