Aug 24

We’ve previously shown how to create an MD5 sum for a file. If you don’t have a file and instead just need an MD5 sum for a byte array then you can achieve it using the following code.

            // Data is the byte array we need an MD5 sum for

            byte[] data = getDataFromWhereever();

            // Get an MD5 implementation of MessageDigest

            MessageDigest md = MessageDigest.getInstance("MD5");

            // Convert the MD5 byte array to a hex string

            String md5 = new BigInteger(1, md.digest(data)).toString(16);

written by objects \\ tags: , , ,

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: ,