Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

JToolBar Question ?

Posted on 2003-11-26
10
483 Views
Last Modified: 2010-03-31
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.setFloatable(false);
    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 :

    http://www.jext.org/index.php?section=gallery&category=2

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

0
Comment
Question by:simple21
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 3

Expert Comment

by:monkesdb
ID: 9829269
try

b1.setBorderPainted(false)
0
 

Author Comment

by:simple21
ID: 9829579
>> 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.
0
 
LVL 9

Expert Comment

by:yongsing
ID: 9829768
Try adding a mouse listener to the buttons. In the mouseEntered() method, do b1.setBorderPainted(true), and in mouseExited method, do b1.setBorderPainted(false);
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 15

Expert Comment

by:Javatm
ID: 9829983
Can you try to give me a sample pls !
0
 
LVL 15

Expert Comment

by:Javatm
ID: 9829993
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
0
 

Author Comment

by:simple21
ID: 9830014
>> 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.
     
0
 
LVL 9

Accepted Solution

by:
yongsing earned 45 total points
ID: 9830069
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 + "");
      buttons[i].setBorderPainted(false);
      buttons[i].addMouseListener(this);
      toolBar.add(buttons[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) {
      ((JButton)source).setBorderPainted(borderPainted);
    }
  }

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

Author Comment

by:simple21
ID: 9834564
Thank you mwah :0
0
 
LVL 9

Expert Comment

by:yongsing
ID: 9834663
Javatm:

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

Expert Comment

by:yongsing
ID: 9834687
Javatm:

I just realized that you have posted a question with points for me. Thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 82
how to install java on RHEL image on EC2 4 39
ejb entity bean example issue 2 16
Crystal Reports Licensing Questions 4 34
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question