2
When working with tables, it may be useful to detect selection changes. If for example, you need to sum the values of a specified column in a selection range, this method will be most essential. If you explore the available methods to add listeners to a JTable, you will notice there’s no such thing as a selectionListener. This is because the JTable has its own selection model, where you can add the listener. The following code illustrates the way to go to add a selection listener: [crayon-5b4cc8e38da3b200514496/]

JTable, detecting selection changes // ListSelectionListener /*Selection Changed ...


When developing user interfaces for management software you usually need to check what the user inputs in order to store the values in a database or a file. Java offers different alternatives to parse a String (normally the way user inputs values to the system) to other data types. The class SimpleDateFormat from the package java.text offers a simple method to do this. You just have to call parse(String youDate) in order to get a java.util.Date. Following you can find some code which explains this method and some of its particularities: [crayon-5b4cc8e38e344484880340/]

SimpleDateFormat to check user date input // parsing String to ...


When printing reports or casting Strings to Numbers, it’s very useful to use the DecimalFormat class found in java.text. This class is pretty straightforward and easy to use, but some problems may be found when your work with this class in computers from other countries. Internationalization will cause your program to behave in a way you may not expect in some cases. If you use this class to parse a number to a String, you may find that when a user enters a number in a french computer you will be getting a ParseException, because the computer is expecting different symbols. […]

Numbers to Strings with custom symbols // DecimalFormat – DecimalFormatSymbols



4
Java is a very powerful object oriented language. If you search for recursion in wikipedia you will find this definition “Recursion, in mathematics and computer science, is a method of defining functions in which the function being defined is applied within its own definition.” This means, that the function will call itself again and again until it gets the correct answer. There are many pages where you can find great explanations to recursion theory. Most of them use the example of the Towers of Hanoi: Cut The Knot –Towers of Hanoi– Recursion –Towers of Hanoi– Java Recursion with examples What […]

Java recursive functions explained // Using recursion to sum an ...


JTable inside JTable cell 11
Java is one of the greatest object oriented languages. This can easily be seen when using swing components. JTables are a great example. Briefly, jTables are just a base to display a matrix of JComponents. So inside a JTable you can embed any object which extends the JComponent class. Today I’ll show you an easy way to display a JTable inside another jTable as a cellRenderer. If you’ve ever worked with multivalued data models this can be of great help. In this simple example I’ll create a small contact manager where the name, phones, and e-mail addresses of the contact […]

Displaying a jTable inside another jTable // JTable cellRenderer


9
Today I’ll show you an easy way to automate your database backup dumps with a java application that runs on the background. This simple app will generate a backup of your database and will name it with today’s date. It’s not really the java program interacting with the database, but the app interacting with the command line program pg_dump. The thing is quite simple. First we generate a filename with today’s date. Then we check if the file exists. Finally we call the pg_dump with the appropriate parameters and the backup is generated [crayon-5b4cc8e38f828153343535/] To run the above programs you […]

Java App for PostgreSQL scheduled backups using pg_dump (Windows only)



53
Jasper Reports is in my opinion by far the best report engine available for Java, even more, it’s open source! In the project page there is enough information available to build simple and some advanced reports. If you need more help you can buy some guides at the project’s owner commercial page JasperSoft There is also technical support available to be purchased. Today I’ll show you how to choose a printer programmatically. [crayon-5b4cc8e38ff23746720517/] In the above code you can see how to accomplish our purpose. The first part of all is generating our JasperPrint, this is common to all methods […]

Choosing a printer programmatically in Jasper Reports


mySaify 8
If you’ve ever tried to run a java program with your windows mobile device you’ll be aware its one of the most difficult tasks. Sun doesn’t officially support windows mobile devices, so you must go to a third party solution. Why hasn’t Sun released an official JVM for ARM pocket PC’s? As you can read in the official Sun forum in the thread Open letter to SUN to produce a JRE for Pocket PC …Unfortunately, since it’s not an officially supported project at Sun (i.e. one that will generate enough revenue based on our projections to cover the costs) it […]

JVM for Windows Mobile (J2ME) // PocketPC – PDA MySaifu


5
When you press the Enter key while in a JTable, you’ll notice how the row selection changes to the next row or to the first row if the former row selected was the last row in the model. You can change this playing with the traversal key policy, but this is quite complicated. The easy way is to consume the event if the enter key has been pressed. You can accomplish this doing the following: [crayon-5b4cc8e390d92483818264/] It’s very important to consume the event during the keyPressed event and not during the other possible keyEvents not doing so will mean that […]

Remove JTable’s Enter Key behavior



JTable Alternate Row Color 7
Java tables are great but complex. The good thing about them is that you can do with them whatever you want. Even more, the view is completely separated from the model so you can even play more. JTables in brief (bad thing) are just a bunch of components put together. So anything you can de to a Component you can do in a JTable. To make a JTable render each row in a different color, you just have to extend the JTable’s prepareRender method. [crayon-5b4cc8e391409126879201/] The above code simply gets the component that was going to be rendered and changes […]

JTable Alternate Row Background


Blojsom Logo 1
This is my first real post after finishing the blojsom setup. It wasn’t the easiest process but the results are quite good. Before choosing Blojsom as the weblog engine I looked at the several alternatives such as Apache roller or Pebble. I finally decided to choose Blojsom because it had an easy install and had support for PostgreSQL. Apache Roller has some more features and is part of the Apache foundation group. But it has a much more complex setup process and has lots of dependencies. Pebble instead is too light weight and doesn’t suffice the requirements for this blog. […]

Blojsom setup finished