5

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

Thank you

AhmadAssaf
  • 3,556
  • 5
  • 31
  • 42

1 Answers1

7

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);
    }
}
MicSim
  • 26,265
  • 16
  • 90
  • 133
  • i have came across this .. but it does not appear to work for me .. it lacks good installation manual .. have u tried it ? can u give me some details please – AhmadAssaf Jan 06 '11 at 18:01
  • 1
    There is no installation necessary. Just create the StarRater widget and use it as you would any other. https://gist.github.com/768277 – I82Much Jan 06 '11 at 18:08
  • this is what i did .. and its not working StarRater starRater = new StarRater(5, 2, 1); starRater.addStarListener(new StarRater.StarListener() { public void handleSelection(int selection) { System.out.println(selection); } }); this.add(starRater); – AhmadAssaf Jan 06 '11 at 18:15
  • i found my error .. i was trying to add it to a JPanel .. so i had to change the layout for that panel .. thanks a lot – AhmadAssaf Jan 06 '11 at 23:49