Let Us Know About Swing Handling In Java
It is advanced than awt controls. It supports images. It occupies less memory than awt controls. Swing controls are called light weight components. awt controls are called heavy weight components. JApplet class is used to display swing controls. Applet class is used to display awt controls. Separate container is created and controls are attached to that container, in swing handling. Applet by default contains container called panel and controls are attached to that panel. javax.swing package is imported for swing compatible controls classes. java.awt package is imported for awt controls classes.
JLabel class creates label control. getContentPane() creates container and attaches to JApplet. JLabel() constructor takes caption, Image Icon object, Horizontal alignment. If layout manager is not set, this alignment is operated otherwise Layout manager alignment is operated. Image Icon object contains image. add() method adds label control to Container.
JButton class creates button control. Its constructor takes caption, Image Icon object. setActionCommand() method sets action string for the button. JTextField class creates text box control. Its constructor takes size of text box. Its setText() sets string to the textbox. getActionCommand() method returns the string which is set by setActionCommand() method. If it is not set, it returns caption. If it is also not set, it returns nothing.
JCheckBox class creates checkbox control. Its contructor takes caption, image. setRolloverIcon() method applies image when mouse cursor is on the check box. setSelectedIcon() method applies image when mouse button is clicked on the checkbox. getItem() method returns initial address of operated checkbox. This address is as Object class. It is type of caste to JCheckBox type. setText() method of JTextField class sets text to textbox.
JRadioButton class creates radio button. Its constructor takes caption, image icon object. radiobutton object is added to ButtonGroup class object. This ButtonGroup groups radio buttons and only one radio button is selected from the group. getActionCommand() method returns caption of radio button. That text is set to textbox by using setText() method. JTextField class is used to create textbox control.
JComboBox class creates combobox control. Its addItem() method adds options to combo box control. getItem() method returns selected item name from combobox control as Object class type. It is type of caste to String class type. setIcon() method of JLabel class sets image to Label control.
JPanel class creates panel control. Panel is rectangle transparent window. It does not contain controls like title bar, menu bar and so on. ScrollPaneConstants class contains static constants for scrollbars.
This constant displays scrollbar though it is not required.
This constant displays scrollbar when it is required.
JTabbedPane class creates tab control. Its addTab() method creates tabs for tab control. This method takes caption, JPanel Instance. JPanel class is used to create panel. It is rectangular, transparent window. It does not contain title bar, menu bar and so on.
JTable class creates table control. Its constructor takes data, headings. That means, its first argument is double dimension array and second argument is single dimension array.
JTree class creates treeview control. Its constructor takes root node. DefaultMutableTreeNode class creates nodes. Its constructor takes caption of node. JTextField class creates textbox control. Its constructor takes text, size. getPathForLocation() method of JTree class returns path from root node to mouse cursor position as TreePath class object. If there is no path, it returns null. setText() method of JTextField class sets text for textbox.
No responses found. Be the first to comment...