This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to add a HTML link to the JMenuBar?  RSS feed

 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, JMenu objects can be added to JMenuBar. What I want to do is add a logo in the end of the JMenuBar. When the user click the logo, a web broswer will pop up to redirect to the link.It's better that the mouse will change to handlike when point to the link.

Can this be done on the JMenuBar? Or you have some better suggestions?
Thanks in advance.
[ August 01, 2006: Message edited by: Loius Wan ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JMenuBar is a container, and so it can contain any type of component.

You would probably just use a JButton for your "link" like component. Instead of text, you would image of your logo as the icon of the button.

You would add a MouseListener to the button and change the mouse pointer to the hand icon in mouseEntered() and change it back in mouseExited().

You would also add an ActionListener to the button and inside of that you would launch the browser with the URL you want. You'll probably want to use one of the many open source libraries that can handle launching the default browser in a cross-platform way - some choices are BrowserLauncher2, Java Desktop Integration Components, or the Bare Bones Browser Launcher.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!