开发者

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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜