Skip to main content

Posts

Simple program which demonstrates Swing/AWT Grid layout

Simple program which demonstrates Swing/AWT Grid layout: This post is intended to the beginners of swing/awt. This below program creates a JFrame with 2 labels, 2 textfields and 2 buttons. import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; /**  * @author Nagasharath Kopalle  *  * Simple program to demontrate Gridlayout  *  */ public class GridLayoutDemo extends JFrame { private JLabel labelName = null; private JTextField textFieldName = null; private JLabel labelPassword = null; private JPasswordField passwordFieldPassword = null; private JButton buttonSubmit = null; private JButton buttonCancel = null; /** * */ public GridLayoutDemo() { initComponents(); } /** * instantiates components and adds properties. */ void initComponents() { this.setTitle("Grid Layout Dem...

Eclipse Java Editor Shortcuts

Eclipse Oxygen Java editor Shortcuts helps in editing source code more comfortably. Frequently used default shortcuts are listed below.  Description Shortcut Delete Line CTRL + D Copy Line CTRL + ALT + Down Arrow Add method level, class level, member level Comments SHIFT + ALT + J Format Java Source code CTRL + SHIFT + F Make line commented CTRL + / Make multiple lines [block] commented   CTRL + SHIFT + / Search selected similar word within the source document CTRL + K Select line from beginning to end SHIFT + End key Select line from end to beginning SHIFT + Home key Select Word by word in same line CTRL + SHIFT + Right Arrow Move line above ALT + Up Arrow Move line below ALT + Down Arrow Shortcuts can ...

Launch Swing GUI always in a dedicated Thread

1. Since Swing is not thread safe, it is not at all a good practice to launch a UI Container like JFrame, JDialog etc in main Thread. 2. Doing so leads to incorrect behavior of java GUI. 3. To avoid this, Swing toolkit has predefined API as part of JFC. 4.    a. SwingUtilities.invokeAndWait(Runnable r);        b. SwingUtilities.invokeLater(Runnable r); 5. Which part of the code must be in UI Thread?         a. setVisible(true);         b. show(); [deprecated]  and c. pack();       6. Call to these methods mentioned in 5(a), 5(b), and 5(c) must happen in one of the methods mentioned in point 4(a) and point 4(b). That's enough. :)          Example :                        public static void main(String[] args){                         ...

File Manager/File Explorer with Swing JTree Component

This post is intended to beginners of java swing toolkit programmers. It is a simple java program which demonstrates the swing based File explorer GUI. import java.awt.GridLayout; import java.io.File; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import java.util.List; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTree; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.event.TreeModelListener; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; /**  * @author NagasharathK  *  */ public class FileExplorer extends JFrame { private JTree fileManagerTree = null; public FileExplorer() { initComponents(); } /** * Initializes components */ private void initComponents() { this.getContentPane().add(new JScrollPane(createFileManagerTree(...

GridLayout: fill the form with gridlayout

Swing controls are of two types they are Containers and components. components are arranged on a containers. example components are JLabel, JButton etc and example containers are JPanel, JFrame and JDialog etc. these components are arranged on a container with the help of layout managers. Few layout managers available in swing toolkit are 1. FlowLayout [Jframe's Default layout manager] 2. GridLayout 3. BorderLayout [JPanel's Default layout manager] 4. GridBagLayout. 5. Custom Layout manager The custom layout amanger is useful to design programmer's own layout manager. Usually this is useful when any of the available layout managers does not give the needy result. apart of these above all layout managers, few third party libraries are also available they are 1. DesignGridLayout 2. Mig Layout etc Design grid Layout Gridlayout is one of the most simple and flexible layout managers. layout manager is used to arrange the components on a container with proper mar...

WMI - Windows Management Instrumentaion

WMI is a windows Library used to get the information like no of processes running currently in the computer and their event notifications like process creation modification and deletion notifications, cumputer's name, version, Win32 processes list etc The information above mentioned can be fetched not only from local PC but also the remote machine too.. WMI can be accessed through a query langauge in two ways they are: 1. WBEMTEST.exe [GUI Tool] 2  WMIC- stands for WMI Commandline tool 3. Programatically [using Powershell and VBScript] 1. wbemtest.exe:       How to start          1. go to start                2.  go to Run                  3. Type wbemtest.exe                  4.  the following window opens up. Queries that can be run with this tool 1. Usual queries 2. Not...