BrowserToolBar.java A basic tool bar for holding multiple buttons. import java.awt.*; import javax.swing.*; /** Part of a small example showing basic use of JToolBar. * Creates a small dockable toolbar that is supposed to look * vaguely like one that might come with a Web browser. * Makes use of ToolBarButton, a small extension of JButton * that shrinks the margins around the icon and puts text * label, if any, below the icon. * */ public class BrowserToolBar extends JToolBar { public BrowserToolBar() { String[] imageFiles = { "Left.gif", "Right.gif", "RotCCUp.gif", "TrafficRed.gif", "Home.gif", "Print.gif", "Help.gif" }; String[] toolbarLabels = { "Back", "Forward", "Reload", "Stop", "Home", "Print", "Help" }; Insets margins = new Insets(0, 0, 0, 0); for(int i=0; i<toolbarlabels .length; i++) { ToolBarButton button = new ToolBarButton("images/" + imageFiles[i]); button.setToolTipText(toolbarLabels[i]); button.setMargin(margins); add(button); } } public void setTextLabels(boolean labelsAreEnabled) { Component c; int i = 0; while((c = getComponentAtIndex(i++)) != null) { ToolBarButton button = (ToolBarButton)c; if (labelsAreEnabled) { button.setText(button.getToolTipText()); } else { button.setText(null); } } } }
Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10314
Categories:Programming Code Examples, Java/J2EE/J2ME, Basic Swing
Tags:Java/J2EE/J2MEBasic Swing
Post Data:2017-01-02 16:04:31
Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada