Results 1 to 2 of 2
  1. #1
    mix99 is offline Member
    Join Date
    Jan 2010
    Posts
    14
    Rep Power
    0

    Default Update GUI after setToolTipText

    HI guys, i have a strange problem. I have an object that extends JLabel and this object is rotated by x degrees in its paintComponent method (using graphics2D method to rotate).. This object have a setToolTipText calling in paintComponentMethod

    paintComponent(Graphics g)
    {

    //code

    setToolTipText("HELLO!");
    }

    this is the problem: inside the JLabel there is an image. When the text (HELLO) disappear, the image under the area of message is clean (appear white). Even if i make a repaint(); this problem remains..do you have some idea? thank you in advance, guys..

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I'm curious: Why set the tool tip text in the paintComponent method?

    You may want to post a small program that demonstrates your problem. When I tried to reproduce it, I failed:
    Java Code:
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    
    import javax.imageio.ImageIO;
    import javax.swing.*;
    
    public class RotateLabel {
      private static final String IMAGE_PATH = "http://duke.kenai.com/misc/Bullfight.jpg";
      private static final int WIDTH = 600;
      private static final int HEIGHT = 500;
    
      private static void createAndShowUI() {
        BufferedImage image = null;
        try {
          image = ImageIO.read(new URL(IMAGE_PATH));
        } catch (MalformedURLException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        }
        if (image == null) {
          return;
        }
        ImageIcon icon = new ImageIcon(image);
        JLabel label = new JLabel(icon) {
          @Override
          protected void paintComponent(Graphics g) {
            Graphics2D g2 = (Graphics2D) g;
            g2.rotate(Math.PI/4, RotateLabel.WIDTH/2, RotateLabel.HEIGHT/2);
            super.paintComponent(g);
          }
        };
        JPanel panel = new JPanel(new BorderLayout());
        panel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
        panel.add(label);
        
        label.setToolTipText("Hello!");
        
        JFrame frame = new JFrame("RotateLabel");
        frame.getContentPane().add(panel);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      }
    
      public static void main(String[] args) {
        java.awt.EventQueue.invokeLater(new Runnable() {
          public void run() {
            createAndShowUI();
          }
        });
      }
    }
    The image rotates, but the tool tip doesn't mess up the image.

Similar Threads

  1. Changing the color of "setToolTipText"
    By Y. Progammer in forum New To Java
    Replies: 7
    Last Post: 02-27-2010, 06:53 PM
  2. Update the GUI in JTable
    By itaipee in forum AWT / Swing
    Replies: 3
    Last Post: 04-12-2009, 12:28 PM
  3. phonebook update
    By nanna in forum New To Java
    Replies: 5
    Last Post: 03-09-2009, 10:13 PM
  4. How to update my jdk???
    By low224 in forum New To Java
    Replies: 4
    Last Post: 01-04-2009, 04:51 PM
  5. Using sql:update tag
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-13-2008, 11:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •