JToolbar
Java Swing Tutorial Explaining the JToolBar Component. A JToolbar contains a number of components whose type is usually some kind of button which can also include separators to group related components within the toolbar. The toolbar can be docked against any of the four edges of a container (panel or a frame). A toolbar can also be made to float.
Toolbars uses BoxLayout, which arranges components in one horizontal row/ vertical column. This layout manager does not force each component to have the same height or width; instead, it uses their preferred height or width, and attempts to align them.
You can adjust the resulting alignment by calling class Component’s methods setAlignmentX() and/or setAlignmentY() on each component.
You can adjust the resulting alignment by calling class Component’s methods setAlignmentX() and/or setAlignmentY() on each component.
JToolbar Source Code
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 javax.swing.JTextField;
import java.awt.*;
import java.awt.event.*;
public class JToolBarDemo extends JFrame {
protected JTextArea textArea;
protected String newline = "\n";
public JToolBarDemo() {
super("ToolBarDemo");
// Create the toolbar.
JToolBar jtbMainToolbar = new JToolBar();
// setFloatable(false) to make the toolbar non movable
addButtons(jtbMainToolbar);
|
Output
Download JToolbar Source Code
Java JToolBar Hierarchy
javax.swing
Class JToolBar
java.lang.Object
java.awt.BorderLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2, Serializable
Class JToolBar
java.lang.Object
java.awt.BorderLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2, Serializable
JToolBar Constructor
JToolBar()
Creates a new tool bar; orientation defaults to HORIZONTAL.
Creates a new tool bar; orientation defaults to HORIZONTAL.
JToolBar(int orientation)
Creates a new tool bar with the specified orientation.
Creates a new tool bar with the specified orientation.
JToolBar(String name)
Creates a new tool bar with the specified name.
Creates a new tool bar with the specified name.
JToolBar(String name, int orientation)
Creates a new tool bar with a specified name and orientation.
Creates a new tool bar with a specified name and orientation.
0 comments:
Post a Comment