JToolBar Question ?

There are several kinds of Toolbars :

1. A Toolbar which has set of buttons which the buttons shows the square borders
    like :

    JToolBar x = new JToolBar();
    JButton b1 = new JButton();  
    JButton b2 = new JButton();

    x.setLayout(new GridLayout(1,2));
    x.add(b1); x.add(b2);

2. Another version of a JToolBar is a Toolbar which has a set of tools but doesnt shows
    the square borders like JButtons, here is a sample :


How do I make a JToolBar like the one on the link ?    

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


simple21Author Commented:
>> b1.setBorderPainted(false)

     I've already tried this before but it only shows the square border when you click it.

     What I wanna do is like the Toolbar of the IE6 on Windows XP. It only shows
     the square border when you put your mouse pointer at the top of the button
     it's like a mouse over w/o having you to click.
Try adding a mouse listener to the buttons. In the mouseEntered() method, do b1.setBorderPainted(true), and in mouseExited method, do b1.setBorderPainted(false);
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Can you try to give me a sample pls !
I'm also trying to do the samething w/ my Java IDE.

As what simple21 said I Probobly like to do that to. Anyways this is
not my question so I'm gonna add a question w/ points if you can
answer it, thanks.

Friend : Javatm
simple21Author Commented:
>> I'm also trying to do the samething w/ my Java IDE

     Fairly advance stuff !. What a imaginative mind. I wish
     I could be like you guys, mwah :0

Yongsing :

Pls. give me a sample cause I dont know how to do that, I'm
knew at programming so pls. bare w/ me.
Here is a demo of my suggestion.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.awt.print.*;

public class ToolBarDemo extends JFrame implements MouseListener {

  public ToolBarDemo() {
    super("Tool Bar Demo");
    JToolBar toolBar = new JToolBar();
    setSize(new Dimension(450, 130));
    getContentPane().add(toolBar, BorderLayout.PAGE_START);
    JButton[] buttons = new JButton[5];
    for (int i = 0; i < buttons.length; i++) {
      buttons[i] = new JButton(i + "");

  public void mouseClicked(MouseEvent e) {}

  public void mouseEntered(MouseEvent e) {
    paintBorder(e, true);

  public void mouseExited(MouseEvent e) {
    paintBorder(e, false);

  public void mousePressed(MouseEvent e) {}

  public void mouseReleased(MouseEvent e) {}
  public void paintBorder(MouseEvent e, boolean borderPainted) {
    Object source = e.getSource();
    if (source instanceof JButton) {

  public static void main(String[] args) {
    (new ToolBarDemo()).setVisible(true);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
simple21Author Commented:
Thank you mwah :0

Where are the points you promised to give me. :-)

I just realized that you have posted a question with points for me. Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.