Reputation: 5596
I want to know how to create a new Swing Control.
My problem resides on the lack of some components on Swing(datepicker for example)
I looked over Stack Overflow(and some others sites) and found some old answers but without success(several links doesn't work anymore).
So could you point me in some direction?
Upvotes: 3
Views: 1698
Reputation: 72544
Creating a Swing component from scratch is a lot of work, so it's probably easier to try to find something on the web first.
For many use cases composing different Swing components is a good solution. All Swing components can contain sub components, for example adding a browse button to a JTextField is fairly easy.
If you really want to go through with creating a whole new control, perhaps this article might give you a boost:
How to Write a Custom Swing Component
Upvotes: 3
Reputation: 13728
There is a very large number of components you can use in your application. Google will help you finding them. An example for a datepicker is JCalendar and Java Swing Date Picker. Just download it, add the jar to your application and use it. You could easily add it as a bean to the palette of your IDE and drag and drop it like a JButton. JCalendar has also a JDayChooser, JYearChooser a couple of spinner beans and a JLocaleChooser. I have been using Kai Toedter' JCalendar a few years and recommend it highly. Localization is simple.
If you want to create your own controls you must create them as Java Beans. The objects must be serializable, have a no argument constructor and accessors and mutators named set, get and is. An old but nice article on JavaBeans is in Java-World. You can study JCalendar's Java sources.
Upvotes: 2
Reputation: 10007
Take a look at SwingX, which sets out to address some of those missing components you've noticed in core Swing!
Believe me, you do not want to implement your own DatePicker. SwingX has one (the JXDatePicker), it works pretty well, take a look at the article here for more.
Upvotes: 2