How do I save preference user settings in Java?

You can use java.util.prefs package. A simple example: // Retrieve the user preference node for the package com.mycompany Preferences prefs = Preferences.userNodeForPackage(com.mycompany.MyClass.class); // Preference key name final String PREF_NAME = “name_of_preference”; // Set the value of the preference String newValue = “a string”; prefs.put(PREF_NAME, newValue); // Get the value of the preference; // default value … Read more

How do I add an image to a JButton

I think that your problem is in the location of the image. You shall place it in your source, and then use it like this: JButton button = new JButton(); try { Image img = ImageIO.read(getClass().getResource(“resources/water.bmp”)); button.setIcon(new ImageIcon(img)); } catch (Exception ex) { System.out.println(ex); } In this example, it is assumed that image is in … Read more

Creating a custom JButton in Java

When I was first learning Java we had to make Yahtzee and I thought it would be cool to create custom Swing components and containers instead of just drawing everything on one JPanel. The benefit of extending Swing components, of course, is to have the ability to add support for keyboard shortcuts and other accessibility … Read more