How to get rid of the border with a JTable / JScrollPane

Use BorderFactory.createEmptyBorder() instead of null… by using: sp.setBorder(createEmptyBorder()); it works. Your main method becomes: public static void main(String[] args) { JFrame frame = new TestScrollPane(); JPanel panel = new JPanel(); JTable table = new JTable(); panel.setLayout(new BorderLayout()); panel.add(new JLabel(“NORTH”), BorderLayout.NORTH); panel.add(new JLabel(“SOUTH”), BorderLayout.SOUTH); JScrollPane sp = new JScrollPane(table); sp.setBorder(BorderFactory.createEmptyBorder()); panel.add(sp, BorderLayout.CENTER); frame.add(panel); frame.setVisible(true); }

Resizing image in Java

If you have an java.awt.Image, resizing it doesn’t require any additional libraries. Just do: Image newImage = yourImage.getScaledInstance(newWidth, newHeight, Image.SCALE_DEFAULT); Obviously, replace newWidth and newHeight with the dimensions of the specified image. Notice the last parameter: it tells the runtime the algorithm you want to use for resizing. There are algorithms that produce a very … Read more

JSpinner Value change Events

The answer is to configure the formatter used in the JFormattedTextField which is a child of the spinner’s editor: formatter.setCommitsOnValidEdit(true); Unfortunately, getting one’s hand on it is as long and dirty as the introductory sentence: final JSpinner spinner = new JSpinner(); JComponent comp = spinner.getEditor(); JFormattedTextField field = (JFormattedTextField) comp.getComponent(0); DefaultFormatter formatter = (DefaultFormatter) field.getFormatter(); … Read more

Window resize event?

Implement a ComponentAdapter with componentResized(): frame.addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent componentEvent) { // do stuff } });