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
Tag: java GUI
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
Very good example of Swing and JDBC code in Java
If you are new to Java Programming and need to understand clearly how Swing GUIs and JDBC work together for GUI and databases, you should have a look at http://www.javabeginner.com/java-swing/java-swing-address-book. One of the best examples available on the net to understand database programming.
Form fields height in Java – how to align correctly
When you create a GridLayout in Java Swing, you should define the main labels and the fields one after another. Then only you get the correct height of the fields. If you define all labels first and then all the fields later, the height of the rows and columns does not align correctly.
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