Swing is a widget toolkit for Java. It is part of Sun Microsystems' Java Foundation Classes (JFC) — an API for providing a graphical user interface (GUI) for Java programs.
Swing was developed to provide a more sophisticated set of GUI components than the earlier Abstract Window Toolkit. Swing provides a native look and feel that emulates the look and feel of several platforms, and also supports a pluggable look and feel that allows applications to have a look and feel unrelated to the underlying platform.ThesisScientist.com
In this tutorial we take you through creating several simple custom components
from scratch using Java Swing as the implementation platform. It is hoped that readers
will get a better understanding of the MVC architecture from this document as well as
find within it a cook-book for creating MVC style custom GUI components for Java
Swing.
In this tutorial we take you through creating several simple custom components
from scratch using Java Swing as the implementation platform. It is hoped that readers
will get a better understanding of the MVC architecture from this document as well as
find within it a cook-book for creating MVC style custom GUI components for Java
Swing.
Java programming, Java Swing Programming, SWING GUI Design, desktop application, Getting Started with Swing application development in java, Introduction to GUI based programming in java, Java to standard edition, J2SE, Core Java, Swing package in java
Swing is a GUI widget toolkit for Java. It is part of Oracle's Java Foundation Classes (JFC) – an API for providing a graphical user interface (GUI) for Java programs.
GUI Programming in JAVA (Using Netbeans) - A ReviewFernando Torres
The powerpoint provides the user with a review of various concepts of GUI programming in JAVA. It covers various concepts like :
1. What is IDE ?
2. Various Methods and Properties of Components
3. Variable declaration
4. Data types
Etc
L0018 - SWT - The Standard Widget ToolkitTonny Madsen
The graphical sub-system of the Eclipse platform is made up of two components: SWT, the Standard Widget Toolkit; and JFace, an architecture independent modeling layer. This module describes how to use SWT in views and editors and how different resources must be managed.
Java programming, Java Swing Programming, SWING GUI Design, desktop application, Getting Started with Swing application development in java, Introduction to GUI based programming in java, Java to standard edition, J2SE, Core Java, Swing package in java
Swing is a GUI widget toolkit for Java. It is part of Oracle's Java Foundation Classes (JFC) – an API for providing a graphical user interface (GUI) for Java programs.
GUI Programming in JAVA (Using Netbeans) - A ReviewFernando Torres
The powerpoint provides the user with a review of various concepts of GUI programming in JAVA. It covers various concepts like :
1. What is IDE ?
2. Various Methods and Properties of Components
3. Variable declaration
4. Data types
Etc
L0018 - SWT - The Standard Widget ToolkitTonny Madsen
The graphical sub-system of the Eclipse platform is made up of two components: SWT, the Standard Widget Toolkit; and JFace, an architecture independent modeling layer. This module describes how to use SWT in views and editors and how different resources must be managed.
HTML stands for Hyper Text Markup Language, which is the most widely used language on Web to develop web pages. and dummies guide to html5 and complete html guide pdf
Ransomware is a type of malicious software that blocks access to data or threatens to publish it until a ransom is paid. Simple ransomware may lock the system in a way which is not difficult for a knowledgeable person to reverse. More advanced malware uses a technique called cryptoviral extortion, in which it encrypts the victim's files, making them inaccessible, and demands a ransom payment to decrypt them and ransomware attacks 2017
How to write a Great Research Paper?
The research paper is a significant piece of academic writing, in which the author performs research on a topic independently and writes a description of the results of that research. It is written to communicate to the community and to contribute to the advancement of knowledge. Types of papers include:
• Inventions
• Progress
• Survey
https://www.ThesisScientist.com
Research process involves a systematic way that focuses on being objective and gathering a multitude of information for analysis so that the researcher can come to a conclusion. Basic steps that should be considered and research process definition pdf and marketing research process 5 steps
How to write a good Dissertation/ Thesis
Thesis refers to a written work on a particular domain resulting from original research. You should introduce your subject area and explain research topic by referring latest published materials instead of old published materials. The objective is to present a simple, clear and complete account of the results of your research.
• Brainstorm or generate ideas for your topic.
• Conduct a thorough literature search before designing your methodology and collecting your data.
Relate your findings to your original statement of the problem and your literature review.
Https://www.ThesisScientist.com
How to write a research paper: How to write a research paper?
The research paper can be considered as the living thing which grows and changes as the student explores, interprets and evaluates sources related to a specific topic. Steps to write a research paper:
• Choose your topic.
• Begin your search.
• Making an outline.
• Write your paper.
A computer user can be tricked or forced into downloading software onto a computer that is of malicious intent. Such software comes in many forms, such as viruses, Trojan horses, spyware, and worms.and internet security tips and tricks
But as we’re stuck with the word ‘teenager’, what do we do? We could use it in a non-judgemental way just to mean those aged 13-19. Or, better still, we could ditch it altogether and take people for what they are, not how they’re labeled.Case Study: I left school at 18 and worked as a teacher. I dressed like a teacher, behaved like a teacher and, as far as I can remember, even thought like a teacher. and how to deal with a lying teenager
driverless car 2020 is a vehicle that is capable of sensing its environment and navigating without human input.[4] Many such vehicles are being developed, but as of May 2017 automated cars permitted on public roads are not yet fully autonomous and driverless car google
the podcast is an episodic series of digital audio files which a user can subscribe to so that new episodes are automatically downloaded via web syndication to the user's own local computer, mobile application, or portable media player.[1] and podcast tips beginners and podcast speaking tips
The science of vastu is related to the branch vedic truth which is very important for creating a natural balance in the life of human beings. Vastu not only helps in your personal growth but also helps in creating a prosperous environment all around you. Every person wants to enhance their career opportunities in order to gain excellent benefits in future. Vastu is science that helps you in many ways, it makes your house and the surroundings around you completely positive, and this in turn helps in improving your career objectives to a great extent. According to the Vastu principles, every person should follow certain rules and regulations in their study and working norm.
Reliance Jio Infocomm Limited, or Jio, is a LTE mobile network operator in India. It is a wholly owned subsidiary of Reliance Industries headquartered in Navi Mumbai, Maharashtra that provides wireless 4G LTE service network (without 2G/3G based services) and is the only 'VoLTE-only' (Voice over LTE) operator in the country which lacks legacy network support of 2G and 3G and reliance jio business model
The relationship between how satisfied a person is with their job and their actual job performance is open to discussion and debate. You see, it's hard to correlate those two aspects primarily. and job satisfaction and performance ande job satisfaction factors
Where should you put your advertising when there a limited number of dollars available? It’s the number one question of business owners as they consider all things marketing. Every media salesperson is going to tell you that you should advertise with them and mistakes in advertising
The very first step towards aiming to become a contributor on top platforms is to build your own brand and online presence.Bigger websites continually require valuable pieces of content to feed the insatiable quest of their audiences; however, they wouldn’t just take on any piece of content or contributor who they aren’t able to trust and verify. and contributor and non contributor
This thesis presents a simulation based analysis of these protocols. We used the combination of EIGRP&IS-IS, RIP&IS-IS routing protocols on the Hybrid network in order to reveal the advantage of one over the other as well as the robustness of each protocol combination and how this is measured.
Dynamic source routing protocol (DSR) is an on-demand protocol designed to restrict the bandwidth consumed by control packets in ad hoc wireless networks by eliminating the periodic table update messages required in the table-driven approach.ad hoc network protocols
Delivering high-quality video content is one of the latest and most demanding challenges faced by the IP. With the deployment of these new IPTV services, the existing network infrastructures will be pushed to their limits. To accommodate the needs of IPTV services, networks must be able to scale to millions of customers and how to setup iptv
Fog computing factory in alliance nearly bovine computing, optimizing the use of this resource. Currently, crush exercise matter is abeyance to the backward, stored and analyzed, limitation which a decision is made and action taken. But this practices isn’t efficient. Utter computing allows computing, honest and action-taking to enter into the picture near IoT belongings and only pushes relevant matter to the cloud. “Fuzz distributes not at all bad quick-wittedness near at the service better accordingly we nub run this torrent of observations,” explains Baker. “So we thus adjustment it newcomer disabuse of uphold data into unalloyed hint go wool-gathering has favour lose concentration gear up gets forwarded up to the cloud. We posterior then heap up it into data warehouses; we bum do predictive analysis.” This beyond to the data-path send away for is enabled by the increased count functionality that manufacturers such as Cisco are building into their edge switches and routers. Fog Computing plays a role. Nonetheless it is a advanced pronunciation, this technology ahead has a designation backing bowels the globe of the modish data centre and the cloud. Bringing details adjust to the user. The middle of facts zoological unbecoming near the unresponsive creates a straightforward convene to cache observations or other help. These services would be located actual to the end-user to proceed on latency concerns and data access. Rather than of conformation inform at data centre sites anent outlandish the end-point, the Fuzz aims to place the data close to the end-user. Creating purblind geographical distribution. Fogginess computing extends forthright clouded advice by creating a help network which sits at numerous points. This, screen, geographically verbose infrastructure helps in numerous ways. Foremost of enclosing, chunky details and analytics arise be unalloyed faster with better results. Gifted-bodied, administrators are able to on ice location-based
One of the most important design problems for multi-UAV (Unmanned Air Vehicle) systems is the communication which is crucial for cooperation and collaboration between the UAVs. If all UAVs are directly connected to an infrastructure, such as a ground base or a satellite, the communication between UAVs can be realized through the in-frastructure. However, this infrastructure based communication architecture restricts the capabilities of the multi-UAV systems. Ad-hoc networking between UAVs can solve the problems arising from a fully infrastructure based UAV networks. In this paper, Flying Ad-Hoc Networks (FANETs) are surveyed which is an ad hoc network connecting the UAVs. The differences between FANETs, MANETs (Mobile Ad-hoc Networks) and VANETs (Vehicle Ad-Hoc Networks) are clarified first, and then the main FANET design challenges are introduced. Along with the existing MANET protocols, open research issues are also discussed.
A review on techniques and modelling methodologies used for checking electrom...nooriasukmaningtyas
The proper function of the integrated circuit (IC) in an inhibiting electromagnetic environment has always been a serious concern throughout the decades of revolution in the world of electronics, from disjunct devices to today’s integrated circuit technology, where billions of transistors are combined on a single chip. The automotive industry and smart vehicles in particular, are confronting design issues such as being prone to electromagnetic interference (EMI). Electronic control devices calculate incorrect outputs because of EMI and sensors give misleading values which can prove fatal in case of automotives. In this paper, the authors have non exhaustively tried to review research work concerned with the investigation of EMI in ICs and prediction of this EMI using various modelling methodologies and measurement setups.
ACEP Magazine edition 4th launched on 05.06.2024Rahul
This document provides information about the third edition of the magazine "Sthapatya" published by the Association of Civil Engineers (Practicing) Aurangabad. It includes messages from current and past presidents of ACEP, memories and photos from past ACEP events, information on life time achievement awards given by ACEP, and a technical article on concrete maintenance, repairs and strengthening. The document highlights activities of ACEP and provides a technical educational article for members.
Water billing management system project report.pdfKamal Acharya
Our project entitled “Water Billing Management System” aims is to generate Water bill with all the charges and penalty. Manual system that is employed is extremely laborious and quite inadequate. It only makes the process more difficult and hard.
The aim of our project is to develop a system that is meant to partially computerize the work performed in the Water Board like generating monthly Water bill, record of consuming unit of water, store record of the customer and previous unpaid record.
We used HTML/PHP as front end and MYSQL as back end for developing our project. HTML is primarily a visual design environment. We can create a android application by designing the form and that make up the user interface. Adding android application code to the form and the objects such as buttons and text boxes on them and adding any required support code in additional modular.
MySQL is free open source database that facilitates the effective management of the databases by connecting them to the software. It is a stable ,reliable and the powerful solution with the advanced features and advantages which are as follows: Data Security.MySQL is free open source database that facilitates the effective management of the databases by connecting them to the software.
We have compiled the most important slides from each speaker's presentation. This year’s compilation, available for free, captures the key insights and contributions shared during the DfMAy 2024 conference.
Online aptitude test management system project report.pdfKamal Acharya
The purpose of on-line aptitude test system is to take online test in an efficient manner and no time wasting for checking the paper. The main objective of on-line aptitude test system is to efficiently evaluate the candidate thoroughly through a fully automated system that not only saves lot of time but also gives fast results. For students they give papers according to their convenience and time and there is no need of using extra thing like paper, pen etc. This can be used in educational institutions as well as in corporate world. Can be used anywhere any time as it is a web based application (user Location doesn’t matter). No restriction that examiner has to be present when the candidate takes the test.
Every time when lecturers/professors need to conduct examinations they have to sit down think about the questions and then create a whole new set of questions for each and every exam. In some cases the professor may want to give an open book online exam that is the student can take the exam any time anywhere, but the student might have to answer the questions in a limited time period. The professor may want to change the sequence of questions for every student. The problem that a student has is whenever a date for the exam is declared the student has to take it and there is no way he can take it at some other time. This project will create an interface for the examiner to create and store questions in a repository. It will also create an interface for the student to take examinations at his convenience and the questions and/or exams may be timed. Thereby creating an application which can be used by examiners and examinee’s simultaneously.
Examination System is very useful for Teachers/Professors. As in the teaching profession, you are responsible for writing question papers. In the conventional method, you write the question paper on paper, keep question papers separate from answers and all this information you have to keep in a locker to avoid unauthorized access. Using the Examination System you can create a question paper and everything will be written to a single exam file in encrypted format. You can set the General and Administrator password to avoid unauthorized access to your question paper. Every time you start the examination, the program shuffles all the questions and selects them randomly from the database, which reduces the chances of memorizing the questions.
6th International Conference on Machine Learning & Applications (CMLA 2024)ClaraZara1
6th International Conference on Machine Learning & Applications (CMLA 2024) will provide an excellent international forum for sharing knowledge and results in theory, methodology and applications of on Machine Learning & Applications.
1. WWW.ThesisScientist.com
Advanced Swing
Swings –
Swing is a widget toolkit for Java. It is part of Sun Microsystems' Java
Foundation Classes (JFC) — an API for providing a graphical user
interface (GUI) for Java programs.
Swing was developed to provide a more sophisticated set of
GUI components than the earlier Abstract Window Toolkit. Swing provides a
native look and feel that emulates the look and feel of several platforms, and
also supports a pluggable look and feel that allows applications to have a look
and feel unrelated to the underlying platform.
Swing is a platform-independent, Model-View-Controller GUI framework for
Java. It follows a single-threaded programming model, and possesses the
following traits:
Features:
Platform independence
Swing is platform independent both in terms of its expression (Java) and its
implementation (non-native universal rendering of widgets).
Extensibility
Swing is a highly partitioned architecture, which allows for the "plugging" of
various custom implementations of specified framework interfaces: Users can
provide their own custom implementation(s) of these components to override
the default implementations. In general, Swing users can extend the framework
by extending existing (framework) classes and/or providing alternative
implementations of core components.
Component-oriented
Swing is a component-based framework. The distinction between objects and
components is a fairly subtle point: concisely, a component is a well-behaved
object with a known/specified characteristic pattern of behavior. Swing objects
asynchronously fire events, have "bound" properties, and respond to a well-
known set of commands (specific to the component.) Specifically, Swing
components are Java Beans components, compliant with the Java Beans
Component Architecture specifications.
2. WWW.ThesisScientist.com
Customizable
Given the programmatic rendering model of the Swing framework, fine control
over the details of rendering of a component is possible in Swing. As a general
pattern, the visual representation of a Swing component is a composition of a
standard set of elements, such as a "border", "inset", decorations, etc.
Typically, users will programmatically customize a standard Swing component
(such as a JTable) by assigning specific Borders, Colors, Backgrounds,
opacities, etc., as the properties of that component. The core component will
then use this property (settings) to determine the appropriate renderers to use
in painting its various aspects. However, it is also completely possible to create
unique GUI controls with highly customized visual representation.
Configurable
Swing's heavy reliance on runtime mechanisms and indirect composition
patterns allows it to respond at runtime to fundamental changes in its settings.
For example, a Swing-based application can change its look and feel at
runtime. Further, users can provide their own look and feel implementation,
which allows for uniform changes in the look and feel of existing Swing
applications without any programmatic change to the application code.
Lightweight UI
Swing's configurability is a result of a choice not to use the native host OS's
GUI controls for displaying itself. Swing "paints" its controls programmatically
through the use of Java 2D APIs, rather than calling into a native user
interface toolkit. Thus, a Swing component does not have a corresponding
native OS GUI component, and is free to render itself in any way that is
possible with the underlying graphics APIs.
However, at its core every Swing component relies on an AWT container, since
(Swing's) JComponent extends (AWT's) Container. This allows Swing to plug
into the host OS's GUI management framework, including the crucial
device/screen mappings and user interactions, such as key presses or mouse
movements. Swing simply "transposes" its own (OS agnostic) semantics over
the underlying (OS specific) components. So, for example, every Swing
component paints its rendition on the graphic device in response to a call to
component.paint(), which is defined in (AWT) Container. But unlike AWT
3. WWW.ThesisScientist.com
components, which delegated the painting to their OS-native "heavyweight"
widget, Swing components are responsible for their own rendering.
This transposition and decoupling is not merely visual, and extends to Swing's
management and application of its own OS-independent semantics for events
fired within its component containment hierarchies. Generally speaking, the
Swing Architecture delegates the task of mapping the various flavors of OS GUI
semantics onto a simple, but generalized, pattern to the AWT container.
Building on that generalized platform, it establishes its own rich and complex
GUI semantics in the form of the JComponent model. A review of the source of
Container java and JComponent java classes is recommended for further
insights into the nature of the interface between Swing's lightweight
components and AWT's heavyweight widgets.
Loosely-Coupled/MVC
The Swing library makes heavy use of
the Model/View/Controller software design pattern, which conceptually
decouples the data being viewed from the user interface controls through which
it is viewed. Because of this, most Swing components have
associated models (which are specified in terms of Java interfaces), and the
programmer can use various default implementations or provide their own. The
framework provides default implementations of model interfaces for all of its
concrete components.
Typically, Swing component model objects are responsible for providing a
concise interface defining events fired, and accessible properties for the
(conceptual) data model for use by the associated JComponent. Given that the
overall MVC pattern is a loosely-coupled collaborative object relationship
pattern, the model provides the programmatic means for attaching event
listeners to the data model object. Typically, these events are model centric (ex:
a "row inserted" event in a table model) and are mapped by the JComponent
specialization into a meaningful event for the GUI component.
For example, the JTable has a model called TableModel that describes an
interface for how a table would access tabular data. A default implementation
of this operates on a two-dimensional array.
The view component of a Swing JComponent is the object used to graphically
"represent" the conceptual GUI control. A distinction of Swing, as a GUI
4. WWW.ThesisScientist.com
framework, is in its reliance on programmatically-rendered GUI controls (as
opposed to the use of the native host OS's GUI controls). Prior to Java 6 Update
10, this distinction was a source of complications when mixing AWT controls,
which use native controls, with Swing controls in a GUI.
Finally, in terms of visual composition and management, Swing favors relative
layouts (which specify the positional relationships between components) as
opposed to absolute layouts (which specify the exact location and size of
components). This bias towards "fluid"' visual ordering is due to its origins in
the applet operating environment that framed the design and development of
the original Java GUI toolkit. (Conceptually, this view of the layout
management is quite similar to that which informs the rendering of HTML
content in browsers, and addresses the same set of concerns that motivated
the former.)
Look and feel
Swing allows one to specialize the look and feel of widgets, by modifying the
default (via runtime parameters), deriving from an existing one, by creating one
from scratch, or, beginning withJ2SE 5.0, by using the skinnable synth Look
and Feel, which is configured with an XML property file. The look and feel can
be changed at runtime, and early demonstrations of Swing frequently provided
a way to do this.
Lists –
If you want to present a set of choices to a user, and a radio button or
checkbox set consumes too much space, you can use a combo box or a list.
The JList component has many more features, and its design is similar to that
of the tree and table components. The list control is somewhat awkward to use
for common cases because you need to manipulate some of the machinery that
makes the general cases possible.
The JList Component
The JList component is similar to a set of checkboxes or radio buttons, except
that the items are placed inside a single box and are selected by clicking on the
items themselves, not on buttons. If you permit multiple selections for a list
box, the user can select any combination of the items in the box.
5. WWW.ThesisScientist.com
To construct this list component, you first start out with an array of strings,
then pass the array to the JList constructor :
String[ ] words= { "quick", "brown", "hungry", "wild", ... };
JList wordList= newJList(words);
List boxes do not scroll automatically. To make a list box scroll, you must
insert it into a scroll pane:
JScrollPane scroll Pane=new JScrollPane(wordList);
You then add the scroll pane, not the list, into the surrounding panel. By
default, the list component displays eight items; use the setVisibleRowCount
method to change that value:
wordList.setVisibleRowCount(4); // displays 4 items
You can set the layout orientation to one of three values:
JList.VERTICAL (the default): arrange all items vertically.
List.VERTICAL_WRAP: start new columns if there are more items than
the visible row count.
List.HORIZONTAL_WRAP: start new columns if there are more items
than the visible row count, but fill them horizontally.
You can also restrict the user to a more limited selection mode with the
setSelectionMode method:
wordList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
/ / select one item at a time
wordList.setSelectionModel(ListSelectionModel.SINGLE_INTERVAL_SELECTlON);
/ / select one item or one range of items
The basic user interface components send out action events when the user
activates them. So u need to add a list selection listener to the list component,
and implement the method
public void valueChanged(ListSelectionEvent evt)
in the listener. When the user selects items, a flurry of list selection events is
generated.
Once you are notified that an event has happened, you will want to find out
what items are currently selected. The getSelectedValues method returns an
6. WWW.ThesisScientist.com
array of objects containing all selected items. Cast each array element to a
string.
Object[ ] values =list.getSelectedValues();
for(Object value : values)
do something with (String) value;
List Models
The most common method for using a list component.
Specify a fixed set of strings for display in the list.
Place the list inside a scroll pane, and
Trap the list selection events.
The JList class is responsible for the visual appearance of the data. It actually
knows very little about how the data are stored-all it knows is that it can
retrieve the data through some object that implements the ListModel interface:
public interface ListModel
{
int getSize () ;
Object getElementAt( int i) ;
void addListDataListener(ListDataListener l) ;
void removeListDataListener(ListDataListener l):
}
Through this interface, the JList can get a count of elements and retrieve each
one of the elements.
7. WWW.ThesisScientist.com
Also, the JList object can add itself as a list data listener. That way, if the
collection of elements changes, JList gets notified so that it can repaint the list.
Adding and removing listeners, has been done in the AbstractListModel class,
which we extend. We only need to supply the getSize and getElementAt
methods:
class WordListModel extends AbstractListModel
{
public WordListModel(int n)
{
length = n;
}
public int getSize()
{
return (int) Math.pow(26,length);
}
public Object getElementAt(int n)
{
II compute nth string
}
(draw diagram on page no 349)
Inserting and Removing Values –
You cannot directly edit the collection of list values. Instead, you must access
the model and then add or remove elements. Suppose you want to add more
values to a list. You can obtain a reference to the model:
ListModel model=list.getModel() ;
But the ListModel interface also has no methods to insert or remove elements
because a list model is that it need not store the elements.
Instead, you should construct a DefaultListModel object, fill it with the initial
values, and associate it with the list.
DefaultListModel model = new DefaultListModel() ;
model.addElement("quick");
model.addElement("brown");
……………
JList list = newJList(model) ;
8. WWW.ThesisScientist.com
Now you can add or remove values from the model object. The model object
then notifies the list of the changes, and the list repaints itself.
model.removeElement( "quick");
model.addElement("slow") ;
Rendering Values –
You can easily represent your list values with any drawing whatsoever.
Although the JList class can display strings and icons automatically, you need
to install a list cell renderer into the JList object for all custom drawing. A list
cell renderer is any class that implements the following interface:
interface ListCellRenderer
{
Component getListCellRendererComponent(JList list,
Object value, int index, boolean isSelected, boolean cell HasFocus) ;
}
This method is called for each cell. It returns a component that paints the cell
contents. The component is placed at the appropriate location whenever a cell
needs to be rendered.
If the rendered image just contains text, an icon, and possibly a change of
color, then you can get by with configuring a JLabel.For eg, to show the font
name in its own font, we can use the following renderer:
class FontCellRenderer extends JLabel implements ListCellRenderer
{
public Component getListCellRendererComponent(JList list, Object value, int
index, boolean isSelected, Boolean cellHasFocus)
{
JLabel label = new JLabel() ;
Font font = (Font) value ;
setText(font.getFamily()) ;
setFont(font) ;
setOpaque(true) ;
setBackground(isSelected?list.getSelectionBackground():list.getBackground());
setForeground(isSelected?list.getSelectionForeground():list.getForeground());
return this ;
}
}
TREES –
9. WWW.ThesisScientist.com
Many tree structures arise in everyday life,such as the hierarchy of countries ,states & cities.The Swing
library has a JTree class for this purpose.The JTree class takes care of laying out the tree and processing
user requests for expanding and collapsing nodes. A tree is composed of nodes.Every node is either a leaf
or it has child nodes.Everynode,with the exception of the root node, has exactly one parent.A tree has
exactly one root node. Sometimes you have a collection of trees, each of which has its own root node.Such
a collection is called a forest.
(draw diagram on page no 358 Fig 6.7 )
Simple Trees -
The JTree component follows the model view-controller pattern. You provide a model of the hierarchical
data, and the component displays it for you. To construct a JTree, you supply the tree model in the
constructor TreeModel model=. . . JTreee tree = new JTree(model) ;
To construct a default tree model, you must supply a root node.
TreeNode root = . . . DefaultTreeModel model= newDefaultTreeModel(root) ;
TreeNode is another interface.
you can simply pass the root node to the JTree constructor.
Then the tree automatically constructs a default tree model :
JTree tree =new JTree(root) ;
Editing Trees and Tree Paths -
The JTree class has a surprising way of identifying nodes in a tree. It doesnot deal with tree nodes, but
with paths of objects,called tree paths. A tree path starts at the root & consists of a sequence of child
nodes.
(draw diagram on page no 366 Fig 6-18)
The JTree class knows nothing about the TreeNode interface.That interace is never used by the TreeModel
interface.it is only used by the DefaultTreeModel implementation.You can have other tree models in which
the nodes do not implement the TreeNode interface at all.If you use a tree model that manages other types
of objects, then those objects may not have getParent & getChild methods. The TreePath class manages a
sequence of Object references.
A number of JTree methods return Treepath objects.When you have a tree path,you usually just need to
Know the terminal node,which you get with the getLastPathComponent method.For eg, to find out the
currently selected node in a tree, you use the getSelectionPath method of the JTree
class.You get a TreePath object back, from which you can retrieve the actual node.
TreePath selectionPath= tree.getSelectionPath() ;
DefaultMutableTreeNode selectedNode =
(DefaultMutableTreeNode)
selectionPath.getLastPathComponent() ;
If you use the insertNodeInto method of the DefaultTreeModel class, the model class takes care of that. For
eg, the following call appends a new node as the last child of the selected node & notifies the tree view.
10. WWW.ThesisScientist.com
model.insertNodelnto(newNode, selectedNode ,
selectedNode.getchildCount()) ;
The analogous call removeNodeFromParent removes a node and notifies the view:
model.removeNodeFromParent (selectedNode) ;
Node Enumeration -
Sometimes you need to find a node in a tree by starting at the root & visiting all children until you have
found a match.The DefaultMutableTreeNode class has several methods for iterating through nodes. The
breadthFirstEnumeration & depthFirstEnumeration methods return enumeration objects whose
nextElement method visits all children of the current node,using either a breadth-first or depth-first
traversal. Breadth-first enumeration is the easiest to visualize.The tree is traversed in layers.The root is
visited first,followed by all of its children, then followed by the grandchildren, and so on.To visualize depth-
first enumeration,imagine a rat trapped in a tree-shaped maze. It rushes along the first path until it comes to
a leaf.Then, it backtracks and turns around to the next path, and so on. The postOrderTraversal method is
a synonym for depthFirstTraversal because the search process visits the childen before visiting the
parents.
Here is the typical usage pattern:
Enumeration breadthFirst = node.breadthFirstEnumeration() ;
while (breadthFirst.hasMoreElements())
do something with breadthFirst. nextElement();
Finally,a method, pathFromAncestorEnumeration, finds a path from an ancestor to a given node and then
enumerates the nodes along that path.
Rendering Nodes-
you will often need to change the way in which a tree component draws the nodes.The most common
change is to choose different icons for nodes and leaves.Other changes might involve changing the font of
the node labels or drawing images at the nodes. All these changes are made possible by installing a new
tree cell renderer into the tree.By default, the JTree class uses DefaultTreeCellRenderer objects to draw
each node.The DefaultTreeCellRenderer class extends the JLabelclass. The label contains the node icon
and the node label.
You can customize the display in three ways :
1. You can change the icons, font, and background color used
by a DefaultTreeCellRenderer.These settings are used for
all nodes in the tree.
2. You can install a renderer that extends the
DefaultTreeCellRenderer class and vary the icons, fonts,
and background color for each node.
3. You can install a renderer that implements the
TreeCellRenderer interface, to draw a custom
image for each node.
To change the appearance of individual nodes,you install a tree cell renderer.The TreeCellRenderer
interface has a single method:
Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
boolean expanded, boolean leaf, int row, boolean hasFocus)
11. WWW.ThesisScientist.com
Custom Tree Models -
The TreeModel interface has only a handful of methods.The first group of methods enables the JTree to
find the tree nodes by first getting the root, then the children.The JTree class calls these methods only
when the user actually expands a node.
Object getRoot ()
int getChildCount(Object parent)
Object getChild(Object parent, int index)
TheTreeModel is responsible for telling the JTree how they are connected.The next method of the
TreeModel interface is the reverse of getChild:
int getlndexOfChild(Object parent,Object child)
The tree model tells the JTree which nodes should be displayed as leaves:
boolean isLeaf(Object node)
If your code changes the tree model, then the tree needs to be notified so that it can redraw itself. The tree
adds itself as a TreeModelListener to the model.Thus, the model must support the usual listener
management methods:
void addTreeModelListener(TreeModelListener l)
void removeTreeModelListener(TreeModelListener l)
When the model modifies the tree contents, it calls one of the four methods of the TreeModelListener
interface:
void treeNodesChanged(TreeModelEvent e)
void treeNodeslnserted(TreeModelEvent e)
void treeNodesRemoved (TreeModelEvent e )
void treeStructureChanged(TreeModelEvent e)
The TreeModelEvent object describes the location of the change.
Finally if the user edits a tree node, your model is called with the change.
Void valueForPathChanged(TreePath path ,Object newValue)
If you don’t allow editing, this method is never called.
Progress Indicators -
A JProgressBar is a Swing component that indicates progress. A ProgressMonitor is a dialog box that
contains a progress bar. A ProqressMonitorInputStream displays a progress monitor
dialog box while the stream is read.
Progress Bars
A progressbar is a simple component-just a rectangle that is partially filled with color to indicate the
progress of an operation. By default, progress is indicated by a string “n% “.
You construct a progress bar much as you construct a slider, by supplying the minimum and maximum
value and an optional orientation:
progressBar = newJProgressBar(0, 1000);
progressBar= newJProgressBar(SwingConstants. VERTICAL, 0, 1000);
12. WWW.ThesisScientist.com
You can also set the minimum and maximum with the setMinimum and setMaximum methods.
Unlike a slider,the progress bar cannot be adjusted by the user. Your program needs to call setValueto
update it.
If you call
progressBar. setStringPainted(true);
the progress bar computes the completion percentage and displays a string ”n% “ .If you want to show a
different string, you can supply it with the setString method:
if (progressBar.getValue() > 900)
progressBar.setString(" AlmostDone ");
Progress Monitor
A ProgressMonitor is a complete dialog box that contains a progress bar.The dialog box contains a Cancel
button.If you click it,the monitor dialog box is closed.In addition,your program can query whether the user
has canceled the dialog box & terminate the monitored action.
You construct a progress monitor by supplying the following:
The parent component over which the dialog box should pop up.
An object that is displayed on the dialog box.
An optional note to display below the object.
The minimum and maximum values. .
As you update the progress value, you should also call the isCanceled method to see if the program user
has clicked the
Cancel button.
When the monitored activity has concluded, call the close method to dismiss the dialog box.You can reuse
the same dialog box by calling start again.
There are two conditions for termination. The activity might have completed, or the user might have
canceled it. In each of these cases, we close down :
The timer that monitored the activity.
The progress dialog box.
The activity itself (by interrupting the thread).
Component Organizers –
These include the split pane, a mechanism for splitting an area into multiple parts whose boundaries canbe
adjusted,the tabbed pane,which uses tab dividers to allow a user to flip through multiple panels,& the
desktop pane.,which can be used to implement applications that display multiple internal frames.