Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A few comments:</p> <p>a) there is no need for you to use a CompoundIcon. The code you posted is using an empty String for the TextIcon.</p> <p>b) you should not nest RotatedIcons. If you nest, the actual rotation will be the sum of all the roatations so the rotation will not be sequentail. If you nest 3 icons with angles of 1, 2, 3, then you are actually rotating a total of 6 degrees, not 3. Right now your code is like:</p> <pre><code>RotatedIcon ri = new RotatedIcon(ri, angle); </code></pre> <p>Instead you should be using:</p> <pre><code>RotatedIcon ri = new RotatedIcon(ri.getIcon(), angle); </code></pre> <p>Here is a restructured version of you code which I think does what you want:</p> <pre><code>import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class IconSSCCE extends JPanel implements ActionListener { JLabel label = new JLabel(); TextIcon text; ImageIcon image; Float angle = 0.0f; public IconSSCCE() { setLayout( new BorderLayout() ); text = new TextIcon(label, "Some Text", TextIcon.Layout.HORIZONTAL); // text = new TextIcon(label, "", TextIcon.Layout.HORIZONTAL); image = new ImageIcon("dukeWaveRed.gif"); CompoundIcon ci = new CompoundIcon(CompoundIcon.Axis.X_AXIS, image, text); label.setIcon( ci ); add(label, BorderLayout.NORTH); JButton rotate = new JButton("Rotate"); add(rotate, BorderLayout.SOUTH); rotate.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { new Timer(50, IconSSCCE.this).start(); } }); } public void actionPerformed(ActionEvent e) { angle++; RotatedIcon ri = new RotatedIcon(image, angle); CompoundIcon ci = new CompoundIcon(ri, text); label.setIcon( ci ); } private static void createAndShowUI() { JFrame frame = new JFrame("IconSSCCE"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add( new IconSSCCE() ); frame.pack(); frame.setLocationRelativeTo( null ); frame.setVisible( true ); } public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { createAndShowUI(); } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload