Search code examples
javaswingrating

Swing star rating


Is there any Swing Star rating widget.. am thinking of implementing my own .. but finding one will save me so much time

Thank you


Solution

  • What about this one:

    Star Rating Panel for Java Swing

    Sample code to use the StarRater (using the example from the comments):

    public class Test {
        public static void main(String[] args) {
            JFrame frame = new JFrame();
            JPanel panel = new JPanel();
            StarRater starRater = new StarRater(5, 2, 1);
            starRater.addStarListener(
                new StarRater.StarListener()   {
    
                    public void handleSelection(int selection) {
                        System.out.println(selection);
                    }
                });
            panel.add(starRater);
            frame.getContentPane().add(panel);
            frame.pack();
            frame.setVisible(true);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
    }