Hello Java Swing Gurus
I am working to create a pure swing Java GUI, that will conform to the Apple Aqua guidelines. Please no negative comments about Swing - Aqua and the Macintosh.
I am trying to add a dividing line just like that found in the System Preferences App. This line separates the Tool Bar icons from the panels below.
As far as I can tell to achieve this Apple used an image that tiled across the background of the toolbar to create the line.
What is the best way to achieve this in Swing, a background image added to JToolBar or maybe just some kind of border or can I just draw a Hrule in Swing.
I am very new to Swing and Java, so take it easy in your explanations. Any help welcome as usual.
This is the code I am using for the toolbar.
<pre>
import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.AbstractButton;
import javax.swing.ImageIcon;
import javax.swing.JTextField;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.*;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
class ToolBar extends JPanel {
public ToolBar() {
//Create the toolbar.
JToolBar toolBar = new JToolBar();
toolBar.setFloatable(false);
addButtons(toolBar);
//Lay out the content pane.
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout());
contentPane.add(toolBar, BorderLayout.NORTH);
add(contentPane);
}
private void addButtons(JToolBar toolBar) {
JButton button = null;
//first button
button = new JButton( "Quit Application", new ImageIcon("images/delete.png"));
button.setVerticalTextPosition(AbstractButton.BOTT OM); // sets vertical position of text
button.setHorizontalTextPosition(AbstractButton.CE NTER); // sets horizontal position of text
button.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(0,5,0,5), button.getBorder() ));
button.setToolTipText("Quit Application");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
toolBar.add(button);
}
}
</pre>
Report abuse |
_
_