Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A good Swing project for learning best practices [closed]

I would like if there is some project developed in Java to learn Swing best practices. I mean an open source project hosted on the Internet through SVN or similar. I've been reading some questions in Stackoverflow about this topic but I would see some projects. Thanks.

like image 544
Jonás Avatar asked Nov 02 '11 17:11

Jonás


People also ask

Which is better JavaFX or swing?

In short, Swing and JavaFX are both GUI toolkits for Java programs. Swing is the old standard toolkit that features a bigger library of GUI elements and mature IDE support. JavaFX is the newer standard with a smaller library, more consistent updates, and consistent MVC support.

How do you close a swing?

There are two options to close Java Swing application one is EXIT_ON_CLOSE and other is DISPOSE_ON_CLOSE . DISPOSE_ON_CLOSE doesn't terminate JVM if any user thread is running. You can also implement window listener to implement your closing mechanism by using System. exit() in Swing application.

What is Swing GUI in Java?

Swing in Java is a lightweight GUI toolkit which has a wide variety of widgets for building optimized window based applications. It is a part of the JFC( Java Foundation Classes). It is build on top of the AWT API and entirely written in java. It is platform independent unlike AWT and has lightweight components.


2 Answers

The way I learned Swing best practices was reading the Swing source code in the JDK and practice. Follow Sun's practices and you'll be on the right path.

Read the implementations of JTable, JTree, JScrollPane, the various LookAndFeels, SwingWorker, SwingUtilities. Their event handling and MVC patterns are extremely complex but very readable, maintainable, and extensible. Essentailly, every time you use a component, go read the source code and understand what and why they do it. Eventually, you'll start doing the same thing.

And most importantly, code. Write some large programs, and you'll start seeing things that don't seem right or optimal. Come on to Stack and find out what you're doing wrong or could do better. Write something else, and do the same.

That said, the following projects have (or probably have) good code:

SwingX - The maintainers of SwingX were Sun/ex-Sun people, and I've always thought of it as unofficial incubator for future Swing features.

Squirrel (A JDBC client) - I haven't actually looked at their source, but I've used the program for years and it doesn't show any of the common flaws in badly written Swing programs. With how powerful it is, and how well it works, I would put money that's its extremely well written.

InfoNode (A powerful docking framework) - I've gone through quite a bit of their code, and its pretty solid.

JFreeChart (A powerful charting library) - Not the greatest code, but much better than average, especially taking into account its an old project that was never really intended to do everything people are using it for. That said, it is very extensible, and I've never had a problem molding it to my needs (which are much, much more than its original intentions).

GlazedLists (A highly performant event-based list library) - Not exactly Swing, but it's event handling is similar to Swing. They also have implementations of Swing models and some custom components that are extremely fast.

JIDE Common Layer: A massive collection of custom components that serves as the basis for their commercial components. I haven't gone through their code, but their components are beautiful, and since their primary focus is commercial Swing components, once again, I'd put money that their code is solid.

like image 70
Reverend Gonzo Avatar answered Oct 16 '22 21:10

Reverend Gonzo


I found it very interesting to see a professional-quality application written in Swing, such as IntelliJ IDEA Community Edition. Now that it's open-sourced, you can check out the code and start digging in. Be forewarned though, there are no comments!

like image 36
Nate W. Avatar answered Oct 16 '22 21:10

Nate W.