1000 Java Tips ebook
Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java
programming articles and tips. Please take your copy here.
Take your copy of free "Java Technology Screensaver"!.
Easy Learn Java: Programming Articles, Examples and Tips - Page 282
1060 Stories (530 Pages, 2 Per Page)
Swing Dev with TableModel Free framework
Free yourself from the burden of the TableModel
The "reintroduction of the Java™ Desktop" underscored this year's
JavaOne conference. A renewed effort on Swing and GUI development doesn't come
as welcome news to those of you who swore off Swing as too slow, too hard to
use, or too ugly. Well, if you haven't worked with Swing lately, you'll be glad
to hear that many of these problems have disappeared. Swing has been reworked to
perform better and to take better advantage of the Java 2D API. The Swing
developers have improved the look and feel support in 1.4 and even more so in
the recently released 5.0. Swing is back and better than ever before.
What the Swing community needs right now are tools to make GUI development a
smoother, easier process. And that's where this article comes in.
This article introduces the TableModel Free (TMF) framework, a GUI
development package that relieves the need to create TableModels (which I'll
TableModels in this article to distinguish them from the new structures I
introduce for the framework) for every JTable; in the process, you'll be able to
make your JTables much more configurable and maintainable.
If you've ever used a JTable, you've also been forced to use a TableModel.
You've probably also noticed that nearly all of the code in each TableModel is
identical to the code in every other TableModel, and the code that is different
doesn't really belong in a compiled Java class anyway. This article will dissect
the current methods of TableModel/JTable design, illustrate the shortcomings of
this design, and show how it hasn't accomplished the true goals of the
Model-View-Controller (MVC) pattern. You will see the framework and code that
makes up the TMF framework -- a combination of code that I've written and
commonly used open source projects. With this framework, developers can reduce
the size of a TableModel from hundreds of lines of code to a single line, and
put the important table information in an external XML file. After reading this
article, you will be able to manage your JTable's data using the single line of
code shown here:
TableUtilities.setViewToModel("tableconfig.xml", "My Table",
MVC problems with JTable and TableModel
MVC has become a very popular UI design pattern, as it cleanly separates out the
business logic from the view of the data. Struts is a very good example of the
MVC design in use on the Web. One of the big initial selling points of Swing was
its use of the MVC -- separating the view from the model -- the idea being that
the code was modular enough that you could swap out the view without changing
any code in the model. I think anyone who has ever worked with JTables and
TableModels will laugh and tell you that that's flat-out impossible. Ideally,
using the MVC design pattern, a developer should be able to substitute a JList
or a JComboBox for a JTable with no change to the code in the model representing
the data. However, you can't do that in Swing. Swing makes it impossible to hot
swap a JTable, JList, and JComboBox into an application, even if all three
components were to provide views of the same data model. That's a big deficiency
in the MVC design with Swing. If you want to swap a JList for a JTable, you must
rewrite the entire model behind the view to accommodate it.
Another MVC deficiency specific to JTable/TableModel is the fact that the view
does not update itself when the model changes. A developer must keep a reference
of the model and call a function so that the model tells the view to update
itself; ideally, however this should just happen without any additional code.
Ultimately, the problem with the design of the JTable and TableModel components
is that they are too intertwined with one another. If you change code in the
JTable, you need to make sure that you haven't broken your TableModel in the
process, and vice versa. In what is supposed to be a design pattern built on
modularity, the current implementation is more a design of dependencies.
The TMF framework better adheres to the MVC goals by more cleanly separating the
tasks of the view and the model in a JTable. Though it doesn't reach the higher
goal of making the components hot swappable, it is a step in the right
1 comment | | Score: 0
Posted by Anonymous on Tuesday, December 21, 2004 (00:00:00) (4546 reads)
Java flaw could lead to Windows, Linux attacks
Java flaw could lead to Windows, Linux attacks
A flaw in Sun Microsystems' plug-in for running Java on a variety of browsers
and operating systems could allow a virus to spread through Microsoft Windows
and Linux PCs.
The vulnerability, found by Finnish security researcher Jouko Pynnonen in April,
was patched last month by Sun, but its details were not made public until
Tuesday. Security information provider Secunia posted information about the flaw
in an advisory that rated it a "highly critical" threat.
The Java plug-in enables small Web programs, known as applets, to run safely on
a user's computer. But the security flaw allows a malicious Web site accessed
through a victim's browser to bypass those protections.
"It allows execution of attacker-supplied code without user interaction
(apart from viewing a Web page) which usually means a 'critical'
classification," Pynonnen stated in an e-mail interview with CNET News.com.
"The same exploit could also be used against various operating systems and
browsers, which makes it more serious," he added. The vulnerability can be
used to attack systems running on Windows or Linux, for example, and using major
browser software such as Microsoft's Internet Explorer and Firefox--meaning a
large number of systems are vulnerable to attack.
An attacker could use the flaw to do anything the victim normally could,
including browse, modify or run files, upload more programs to the victim's
system, or send out data from the system, Pynnonen wrote in an advisory dated
While the major browsers have had to deal with a significant number of security
issues, the flaw is a rare black eye for the security of Sun's Java technology.
Java is designed to be able to run programs downloaded from the Internet on
various operating systems safely, without danger to a PC. The
"sandbox" that cordons off Java applets from the rest of the system
has typically worked well.
execute functions of Java that were never meant to be run by external programs.
Last week, while announcing details of Sun's forthcoming Solaris 10 operating
system, President Jonathan Schwartz noted that Java hasn't been afflicted by a
single Java virus.
However, the new security hole could allow a virus to use the Java plug-in to
invade PC systems. In October, a flaw in the Java plug-in for cell phones raised
the specter that a malicious program disguised as a helpful application could
attack a phone's software, if run by a user.
8 comments | | Score: 5
Posted by jalex on Monday, December 20, 2004 (00:00:00) (3125 reads)