Delete all rows from a Java JTable with a custom TableModel

I want to clear all rows in a custom TableModel. Unfortunately, a custom TableModel in Java does not allow use of most efficient of row clearing methods, which only applies to a DefaultTableModel like that shown below: myTableModel.getDataVector().removeAllElements(); myTableModel.fireTableDataChanged(); To do an all clear like the above, for a custom TableModel, you need to reset … Continue reading Delete all rows from a Java JTable with a custom TableModel

Use JTextPane in Java with HTML to print reports

We are all familiar with the Java Swing class JTextArea. Java also has a method called print associated with the JComponent class that can be used to print a JTextArea contents onto a printer. JTextArea jt = new JTextArea();┬ájt.setText("whatever text you desire"); jt.print(); The above code segment will print the contents of the JTextArea jt … Continue reading Use JTextPane in Java with HTML to print reports

How to print a date in the default JTable.print() header and setup the page

After a struggle, managed to figure out that the MessageFormat is not that complicated at all. All I wanted was to print a heading on each page of the JTable with the current date in it. The heading was to read "Report as on " + today's date. Here is how I accomplished the task. … Continue reading How to print a date in the default JTable.print() header and setup the page

Java compilation Error: no suitable constructor found for Box(int)

I spent a lot of time trying to figure out why my Java program was giving me a compilation error on the Box constructor that said Error: no suitable constructor found for Box(int). My attempt was to simply use the Box class in the Swing Library. I figured out why. It so happens that in … Continue reading Java compilation Error: no suitable constructor found for Box(int)

Use Windows Builder from Google to create GUIs in Java quickly

If you use Eclipse to create Java programs, you would know that there are several plugins that enable Eclipse to do magic. However, the Google Windows Builder plugin available from the eclipse market place, almost proves it can make "coffee". Using Windows Builder, you can create GUI windows using Swing, SWT or XWT in minutes. … Continue reading Use Windows Builder from Google to create GUIs in Java quickly