Swing Components - Updated JRadioButton, Combobox and Jscrollpane, Tabbedpane, Tree
Swing Components - Updated JRadioButton, Combobox and Jscrollpane, Tabbedpane, Tree
pane. vsb and hsb are int constants that define when
vertical and horizontal scroll bars for this scroll pane are
ScrollPaneConstants interface.
Constant Description
JScrollBar Constants
Program Using JScrollPane
import java.awt.*; for(int j = 0; j < 20; j++) {
import javax.swing.*;
jp.add(new JButton("Button "
import java.applet.*;
+ b));
/*<applet code="jscroll" width=300
height=250> ++b;
</applet>*/ }
public class jscroll extends JApplet }
{
// Add panel to a scroll pane
public void init()
int v =
{
ScrollPaneConstants.VERTICAL_S
Container contentPane = CROLLBAR_ALWAYS;
getContentPane();
int h =
// Add 400 buttons to a panel
ScrollPaneConstants.HORIZONTA
JPanel jp = new JPanel(); L_SCROLLBAR_AS_NEEDED;
jp.setLayout(new GridLayout(20,
20));
JScrollPane jsp = new
JScrollPane(jp, v, h);
int b = 0;
// Add scroll pane to the content
for(int i = 0; i < 20; i++) {
pane
Output
Program Using JScrollPane
import java.awt.*;
import javax.swing.*;
import java.applet.*;
/*<applet code="jscroll2" width=300 height=250>
</applet>*/
public class jscroll2 extends JApplet
{
public void init()
{
Container co = getContentPane();
JButton b1=new JButton("ok");
JButton b2=new JButton("exit");
JPanel jp =new JPanel();
jp.add(b1);
jp.add(b2);
//Add panel to a scroll pane
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(jp, v, h);
// Add scroll pane to the content pane
co.add(jsp);}}
JTable
A table is a component that displays
rows and columns of data. We can
drag the cursor on column boundaries
to resize columns. We can also drag a
column to a new position. Tables are
implemented by the JTable class,
which extends JComponent.
Constructor of JTable
The DefaultMutableTreeNode
class implements the
MutableTreeNode interface It
represents a node in a tree.
JTree
One of its constructors is shown
here:
DefaultMutableTreeNode(Objec
t obj)
Here, obj is the object to be
enclosed in this tree node.
JTree
To create a hierarchy of tree
nodes, the add( ) method of
DefaultMutableTreeNode can
be used. Its signature is shown
here: