ToolBarButton.java A simple button that contains an image and a label for use in a toolbar. import java.awt.*; import javax.swing.*; /** Part of a small example showing basic use of JToolBar. * The point here is that dropping a regular JButton in a * JToolBar (or adding an Action) in JDK 1.2 doesn’t give * …
Category: FromSitesTree.com
May 05
Basic tool bar for holding multiple buttons. #Programming Code Examples #Java/J2EE/J2ME #Basic Swing
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 …
May 05
Simple button that the user can select to load the entered URL. #Programming Code Examples #Java/J2EE/J2ME #Basic Swing
JIconButton.java A simple button that the user can select to load the entered URL. import javax.swing.*; /** A regular JButton created with an ImageIcon and with borders * and content areas turned off. * */ public class JIconButton extends JButton { public JIconButton(String file) { super(new ImageIcon(file)); setContentAreaFilled(false); setBorderPainted(false); setFocusPainted(false); } } Note: Brought from …
May 05
Simple example illustrating the use of check boxes #Programming Code Examples #Java/J2EE/J2ME #Basic Swing
JCheckBoxTest.java Simple example illustrating the use of check boxes. import javax.swing.*; import java.awt.event.*; */ public class JCheckBoxTest extends JPanel implements ItemListener, ActionListener{ JCheckBox checkBox1, checkBox2; public JCheckBoxTest() { checkBox1 = new JCheckBox("Java Servlets"); checkBox2 = new JCheckBox("JavaServer Pages"); checkBox1.setContentAreaFilled(false); checkBox2.setContentAreaFilled(false); checkBox1.addItemListener(this); checkBox2.addActionListener(this); add(checkBox1); add(checkBox2); } public void actionPerformed(ActionEvent event) { System.out.println("JavaServer Pages selected: " + …
May 05
A simple example that illustrates creating panels #Programming Code Examples #Java/J2EE/J2ME #Basic Swing
A simple example that illustrates creating panels. In Swing, a JPanel can contain custom borders. Typically, utility methods in the BorderFactory class are used to create a border for the panel. Uses the following class: * SixChoicePanel.java A JPanel that displays six radio buttons with labels. import java.awt.*; import javax.swing.*; /** Simple example illustrating the …
May 05
Creates three common types of sliders #Programming Code Examples #Java/J2EE/J2ME #Basic Swing
Creates three common types of sliders: one without tick marks, one with tick marks, and one with both tick marks and labels. import java.awt.*; import javax.swing.*; /** Simple example illustrating the use of JSliders, especially * the ability to specify tick marks and labels. * * */ public class JSliders extends JFrame { public static …
May 05
A JPanel that displays six radio buttons with labels. #Programming Code Examples #Java/J2EE/J2ME #Basic Swing
A JPanel that displays six radio buttons with labels. import java.awt.*; import javax.swing.*; /** A JPanel that displays six JRadioButtons. * *. */ public class SixChoicePanel extends JPanel { public SixChoicePanel(String title, String[] buttonLabels) { super(new GridLayout(3, 2)); setBackground(Color.lightGray); setBorder(BorderFactory.createTitledBorder(title)); ButtonGroup group = new ButtonGroup(); JRadioButton option; int halfLength = buttonLabels.length/2; // Assumes even length …
May 05
Demonstrates the use of a JColorChooser which presents a dialog with three different tabbed panes to allow the user to select a color preference #Programming Code Examples #Java/J2EE/J2ME #Basic Swing
Demonstrates the use of a JColorChooser which presents a dialog with three different tabbed panes to allow the user to select a color preference. The dialog returns a Color object based on the user’s selection or null if the user entered Cancel. import java.awt.*; import java.awt.event.*; import javax.swing.*; /** Simple example illustrating the use of …
May 05
Demonstrates the use of a JColorChooser which presents a dialog with three different tabbed panes to allow the user to select a color preference #Programming Code Examples #Java/J2EE/J2ME #Basic Swing
Demonstrates the use of a JColorChooser which presents a dialog with three different tabbed panes to allow the user to select a color preference. The dialog returns a Color object based on the user’s selection or null if the user entered Cancel. import java.awt.*; import java.awt.event.*; import javax.swing.*; /** Simple example illustrating the use of …
May 05
Creates various buttons. In Swing #Programming Code Examples #Java/J2EE/J2ME #Basic Swing
import java.awt.*; import javax.swing.*; /** Simple example illustrating the use of JButton, especially * the new constructors that permit you to add an image. * */ public class JButtons extends JFrame { public static void main(String[] args) { new JButtons(); } public JButtons() { super("Using JButton"); WindowUtilities.setNativeLookAndFeel(); addWindowListener(new ExitListener()); Container content = getContentPane(); content.setBackground(Color.white); content.setLayout(new …
