Aug 20

There’s a method in JComponent called scrollRectToVisible() which interacts with the parent scroll pane (if one exists) to change its viewport. It takes a Rectangle as an argument that specifies the area you want to be visible in the viewport.

So for example to scroll to a given row in a JTable you would use something like this:

table.scrollRectToVisible(
   new Rectangle(
      0, row * table.getRowHeight(),
      table.getWidth(), table.getRowHeight()));

written by objects \\ tags: ,

May 25

If you have a CSV (or TSV) that you need to display in a JTable then you should have a look at the TableModelExtTextLoader class from SwingLabs.

It provides all you should need and save you the hassle of reinventing the wheel and using a half baked CSV implementation.

Here is an example of it’s usage.

URL csv = new URL("http://myapp/employees.csv");
DefaultTableModelExt data = new DefaultTableModelExt(url);
TableModelExtTextLoader loader = 
        new TableModelExtTextLoader(",", false, 75);
data.setLoader(loader);
data.startLoading();

As many of you will probably have a file from disk that you want to load then see “How to convert a File to a URL”

written by objects \\ tags: , , ,

Jan 28
table.setTableHeader(null);

written by objects \\ tags: ,