Write A Short Note On The Advantages/features of JFC
Write A Short Note On The Advantages/features of JFC
1.
2.
3.
Swing text components display text and optionally allow the user to edit the text.
Programs need text components for tasks ranging from the straightforward (enter a
word and press Enter) to the complex (display and edit styled text with embedded
images in an Asian language).
Swing provides six text components, along with supporting classes and interfaces that
meet even the most complex text requirements. In spite of their different uses and
capabilities, all Swing text components inherit from the same superclass,
JTextComponent, which provides a highly-configurable and powerful foundation for
text manipulation.
The following figure shows the JTextComponent hierarchy.
Group
Text Controls
Plain Text
Areas
Description
Also known simply as text fields, text
controls can display only one line of
editable text. Like buttons, they generate
action events. Use them to get a small
amount of textual information from the
user and perform an action after the text
entry is complete.
JTextArea can display multiple lines of
editable text. Although a text area can
display text in any font, all of the text is in
the same font. Use a text area to allow the
user to enter unformatted text of any length
or to display unformatted help information.
Swing Classes
JTextField and its
subclasses
JPasswordField
And
JFormattedTextField
JTextArea
Styled Text
Areas
JEditorPane
and its subclass
JTextPane
5.
TreeNode getParent()
Methods of MutableTreeNode
void insert(MutableTreeNode Adds child to the receiver at index.
child, int index)
void
setParent(MutableTreeNode
newParent)
Methods of DefaultMutableTreeNode
void
add(MutableTreeNode Removes newChild from its parent and makes it
newChild)
a child of this node by adding it to the end of this
node's child array
int getChildCount()
Returns the number of children of this node.
TreeNode[] getPath()
Returns the path from the root, to get to this
node.
TreeNode getRoot()
Returns the root of the tree that contains this
node.
boolean isRoot()
Returns true if this node is the root of the tree.
Create the object of the tree with the topmost node as argument
iii) Use the add method to create the hierarchy
iv) Create the object of JScrollPane and add the JTree to it. Add the scroll pane to the
content pane.
Event Handling. (2 marks)
The JTree generates a TreeExpansionEvent which is in the package javax.swing.event.
The getPath() of this class returns a TreePath object that describes the path to the changed
node.
The addTreeExapnsionListener and removeTreeExpansionListener methods allows
listeners to register and unregister for the notifications. The TreeExpansionListener
interface provides two methods
void treeCollapsed(TreeExpansionEvent
Called whenever an item in the tree has
event)
been collapsed
void treeExpanded(TreeExpansionEvent
Called whenever an item in the tree has
event)
been expanded
changes.
Example:
import java.awt.*;
import
java.awt.event.*;
import javax.swing.*;
import
javax.swing.tree.*;
/*<applet code="JTreeEvents" width=300 height=300>
</applet>*/
public class JTreeEvents extends JApplet
{
JTree tree;
JTextField jtf;
public void init()
{
Container contentPane=getContentPane();
contentPane.setLayout(new BorderLayout());
DefaultMutableTreeNode top=new DefaultMutableTreeNode("Options");
DefaultMutableTreeNode a=new DefaultMutableTreeNode("A");
top.add(a);
DefaultMutableTreeNode a1=new DefaultMutableTreeNode("A1");
a.add(a1);
DefaultMutableTreeNode b=new DefaultMutableTreeNode("B");
top.add(b);
DefaultMutableTreeNode b1=new DefaultMutableTreeNode("B1");
b.add(b1);
tree=new JTree(top);
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp=new JScrollPane(tree,v,h);
contentPane.add(jsp,BorderLayout.CENTER);
}
}
6.
int