Swing Features and Components
Swing Features and Components
• VERTICAL_SCROLLBAR_ALWAYS
– Vertical scroll bar is always provided.
• HORIZONTAL_SCROLLBAR_ALWAYS
– Horizontal scroll bar is always provided.
• VERTICAL_SCROLLBAR_AS_NEEDED
– Vertical scroll bar is provided as per the need.
• HORIZONTAL_SCROLLBAR_AS_NEEDED
– Horizontal scroll bar is provided as per the need.
import javax.swing.*;
import java.awt.event.*;
public class scroll {
public static void main(String[] args) {
String s="Welcome to Java Swing programming!!!!! This shows the working of
JScrollPane.....";
JTextArea t=new JTextArea(s,10,10);
JFrame f=new JFrame("Frame");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p=new JPanel();
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane sp=new JScrollPane(t,v,h);
p.add(sp);
f.add(p);
f.setSize(200,200);
f.setVisible(true);
}
}
JTable
The JTable class is used to display the data on
two dimensional tables of cells.
setSize(300,400);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new MyJTable();
}
}
JTabbedPane
JTabbedPane is a container component that
lets the user switch between pages by clicking
on a tab.
Constructors for JTabbedPane
➢ JTabbedPane()
Creates an empty TabbedPane with a default tab
placement of JTabbedPane.TOP.
➢ JTabbedPane(int tabPlacement)
Creates an empty TabbedPane with the specified
tab placement of either: JTabbedPane.TOP,
JTabbedPane.BOTTOM, JTabbedPane.LEFT, or
JTabbedPane.RIGHT.
➢ JTabbedPane(int tabPlacement, int tabLayoutPolicy)
Creates an empty TabbedPane with the specified
tab placement and tab layout policy.
import javax.swing.*;
/* <applet code="exp43" width=400 height=100> </applet> */