|
Java™ by example!
|
|
|
How do I change the border of my JToolBar?
 ToolBarTest.java:
 import java.awt.event.*; import javax.swing.*; import java.awt.*; public class ToolBarTest extends JFrame implements ActionListener { JToolBar myToolBar = null; public ToolBarTest () { /** * create the Toolbar */ myToolBar = new JToolBar( JToolBar.HORIZONTAL ); myToolBar.setFloatable( false ); /** * first Toolbar-Button */ JButton button1 = new JButton( "BevelBorder" ); button1.addActionListener( this ); myToolBar.add( button1 ); /** * second Toolbar-Button */ JButton button2 = new JButton( "LineBorder" ); button2.addActionListener( this ); myToolBar.add( button2 ); /** * third Toolbar-Button */ JButton button3 = new JButton( "No Border" ); button3.addActionListener( this ); myToolBar.add( button3 ); /** * set BorderLayout for the contentPane and add the toolbar */ getContentPane().setLayout( new BorderLayout() ); getContentPane().add( myToolBar, BorderLayout.NORTH ); pack(); } public static void main ( String args[] ) { /** * create the ToolBarTest-frame */ ToolBarTest frame = new ToolBarTest(); frame.addWindowListener(new WindowAdapter() { public void windowClosing (WindowEvent e) { System.exit( 0 ); } }); /** * display the frame */ frame.pack(); frame.setVisible( true ); } public void actionPerformed ( ActionEvent e ) { /** * set the specified Border with BorderFactory... */ if ( e.getActionCommand().equals( "BevelBorder" ) ) { myToolBar.setBorder( BorderFactory.createRaisedBevelBorder() ); } else if ( e.getActionCommand().equals( "LineBorder" ) ) { myToolBar.setBorder( BorderFactory.createLineBorder( Color.black, 2 ) ); } else if ( e.getActionCommand().equals( "No Border" ) ) { myToolBar.setBorder( BorderFactory.createEmptyBorder() ); } } }
|
Further Information
Author of answer: Peter Taucher
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|