JToolTip alignment issues
I have a JToolTip attached to the onclick event of a JTextField.
I want the JToolTip to popup aligned with the right edge of the JTextField instead of its left edge as it does by default.
Is there an开发者_开发百科y way to set this?
Override getTooltipLocation(...) of the component your clicking on!
public static void main(String... args) throws IOException {
    final JFrame frame = new JFrame("Test");
    JTextField field = new JTextField() {
        @Override
        public Point getToolTipLocation(MouseEvent event) {
            Rectangle position = frame.getBounds();
            return new Point(position.x, position.y);
        }
    };
    field.setToolTipText("test");
    frame.add(field);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 300);
    frame.setVisible(true);
}
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论