This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to display toolbars like forte4java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to display toolbars like forte4java" Watch "How to display toolbars like forte4java" New topic
Author

How to display toolbars like forte4java

Garry Kalra
Ranch Hand

Joined: May 25, 2001
Posts: 111
Hi,
Does anybody know how to display toolbars like those in forte4java and vc++.
If we use the JToolbar then the toolbar is a much broader one.
Also i was using Actions so that i just have to add them to the menu's and the toolbar. But i am not able to display the icons in the toolbar or the menu. Can somebody help me regarding this.
garry
Rajendar Goud
Ranch Hand

Joined: Mar 06, 2002
Posts: 220
Hi ,
i dont think that the Toolbar will be wide or some thing like that .i tried the example and it works fine for me.
import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.*;
public class ToolBarDemo extends JFrame {
protected JTextArea textArea;
protected String newline = "\n";
public ToolBarDemo() {
//Do frame stuff.
super("ToolBarDemo");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
//Create the toolbar.
JToolBar toolBar = new JToolBar();
addButtons(toolBar);
//Create the text area used for output.
textArea = new JTextArea(5, 30);
JScrollPane scrollPane = new JScrollPane(textArea);
//Lay out the content pane.
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout());
contentPane.setPreferredSize(new Dimension(400, 100));
contentPane.add(toolBar, BorderLayout.NORTH);
contentPane.add(scrollPane, BorderLayout.CENTER);
setContentPane(contentPane);
}
protected void addButtons(JToolBar toolBar) {
JButton button = null;
//first button
button = new JButton(new ImageIcon("images/left.gif"));
button.setToolTipText("This is the left button");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
displayResult("Action for first button");
}
});
toolBar.add(button);
//second button
button = new JButton(new ImageIcon("images/middle.gif"));
button.setToolTipText("This is the middle button");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
displayResult("Action for second button");
}
});
toolBar.add(button);
//third button
button = new JButton(new ImageIcon("images/right.gif"));
button.setToolTipText("This is the right button");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
displayResult("Action for third button");
}
});
toolBar.add(button);
}
protected void displayResult(String actionDescription) {
textArea.append(actionDescription + newline);
}
public static void main(String[] args) {
ToolBarDemo frame = new ToolBarDemo();
frame.pack();
frame.setVisible(true);
}
}
Raj
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to display toolbars like forte4java
 
Similar Threads
How to update a JFrame?
Having more than one JToolbar
Scrollable / Collapsible ToolBar
Adding 'Save All' button to Eclipse toolbar - How?
Problem with JToolBar