Java SWT Tooltips


Forum Post 0 Answers Java SWT Tooltips

0 down vote favorite


Please help me out on this, I have been breakin my head over this for weeks together.

I have a Class called InformationArea.java which displays an information area to the user. There a label called "enter a unique name" in the infomation area(basically an import dialog window). When I hover the mouse over that label there is a empty tooltip being displayed. I would want to remove that tooltip(I mean I dont want it to be shown). I can easily say tooltip.setVisibility(false) but I should not change the code inside the MouseTrackListener Anonymous class. I need to use a toltip property pr anythin else so that when I extend this class I need to have an option to easily set the visibility of this tooltip if needed or disable it if not needed.

Here is my Code snippet (JAVA SWT)

tooltip = new ToolTip(parent.getShell(), SWT.NONE);

MouseTrackListener mouseTrackListener = new MouseTrackListener() {
@Override
public void mouseEnter(MouseEvent e) {
if (text != null && !text.isEmpty()) {
tooltip.setLocation(Display.getCurrent().getCursorLocation().x,
Display.getCurrent().getCursorLocation().y + TOOLTIP_OFFSET_Y);
tooltip.setVisible(true);
}
}

@Override
public void mouseExit(MouseEvent e) {
if (text != null && !text.isEmpty()) {
tooltip.setVisible(false);
}
}

@Override
public void mouseHover(MouseEvent e) {
{
}};

label.addMouseTrackListener(mouseTrackListener);
iconLabel.addMouseTrackListener(mouseTrackListener);

I want an option such that the tooltip can be built or destroyed when ever needed in the derived class without changin the code in the MouseTrackListener

- prithvirulzzz February 26, 2014 | Flag |






Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More