Creating Calendar GUI widget using the AtCalendar class
Create: Following code sample shows how simple it is to create and display a Java calendar widget into your GUI application.
Attach a ActionListener: You must add an action listener to the calendars 'Ok' and 'Cancel' buttons in order to receive the events when the user close the AtCalendar by pressing any of these two buttons. Here is the code segment to attach a listener to the buttons. By default, the buttons do not have any listeners attached to them and therefore the calendar component will not be closed until you explicitly close the calendar with your code.
calendar.addActionListener(new ActionListener() {
public void
actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
if (actionCommand.equals(AtCalendar.OK_ACTION_COMMAND)) {
java.util.Date dt = calendar.getTime();
java.util.Date dt2 = new java.util.Date(calendar.getTimeInMillis());
System.out.println("AtCalendar:getTime(): " + dt);
System.out.println("AtCalendar:getTimeInMillis(): " + dt2);
frame.dispose();
}else if (actionCommand.equals(AtCalendar.CANCEL_ACTION_COMMAND)) {
frame.dispose();;
}
}
});
Following is the complete source code of the CalendarDemo calendar application that has used the AtCalendar widget in its GUI.
//CalendarDemo.java
package demo;
import com.activetree.swing.AtInsetsPanel;
import com.activetree.utils.AtLAFUtil;
import com.activetree.utils.AtComponentUtil;
import com.activetree.view.AtCalendar;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import java.util.Calendar;
public class CalendarDemo extends JFrame {
private com.activetree.view.AtCalendar dateChooser
= new com.activetree.view.AtCalendar(Calendar.getInstance());
public static void main(String[] args) {
try {
AtLAFUtil.setWindowsLookAndFeel();
}catch(Exception ex) {}
new CalendarDemo().setVisible(true);
}
public CalendarDemo() {
setTitle("AtCalendar Demo");
setupContentPane();
addWindowCloseOperation();
addButtonActionListener();
//setSize(new Dimension(230, 265));
}
private void setupContentPane() {
AtInsetsPanel top = new AtInsetsPanel();
top.setLayout(new BorderLayout());
top.add(dateChooser, BorderLayout.CENTER);
setContentPane(top);
pack();
AtComponentUtil.centerOnScreen(this);
}
private void addWindowCloseOperation() {
addWindowListener(new WindowAdapter() {
public void
windowClosing(WindowEvent e) {
close();
}
});
}
private void addButtonActionListener() {
dateChooser.addActionListener(new
ActionListener() {
public void
actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
if (actionCommand.equals(AtCalendar.OK_ACTION_COMMAND)) {
java.util.Date dt = dateChooser.getTime();
java.util.Date dt2 = new java.util.Date(dateChooser.getTimeInMillis());
System.out.println("AtCalendar:getTime(): " + dt);
System.out.println("AtCalendar:getTimeInMillis(): " + dt2);
close();
}else if (actionCommand.equals(AtCalendar.CANCEL_ACTION_COMMAND)) {
close();
}
}
});
}
private void close() {
dispose();
System.exit(0);
}
}
Creating Time enterable UI controls using AtTimeField class
There are two constructors in the AtTimeField class. The default constructor takes no arguments and shows a Time field initialized with the system current hour, minutes, and seconds. You can pass a calendar object to the other constructor to initialize the hour, minute, and second field in the time widget.
Once a AtTimeField widget is created its ui field values such as HOUR, MINUTE, and SECOND can be reset to any other values programmatically using the settter and getter fiels as show below.
Shown next is the complete source code of the TimeFieldDemo example. It shows one AtTimeField and two time labels (startTime and endTime). The time labels displays date and time using the AtCalendar widgets. If you want to change the start date and time or the end date and time click on the icons next to the time labels.
//TimeFieldDemo.java
package demo;
import com.activetree.utils.AtComponentUtil;
import com.activetree.utils.AtLAFUtil;
import com.activetree.view.AtTimeField;
import com.activetree.view.AtCalendar;
import com.activetree.swing.AtInsetsPanel;
import com.activetree.swing.AtStringCellWidget;
import com.activetree.swing.AtImageCellWidget;
import com.activetree.resource.AtCommon;
import com.activetree.resource.AtImageList;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.border.BevelBorder;
import java.awt.*;
import java.awt.event.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Vector;
public class TimeFieldDemo extends JFrame implements ActionListener {
public static void main(String[] args) {
AtLAFUtil.setWindowsLookAndFeel();
new TimeFieldDemo().setVisible(true);
}
private AtTimeField time = new AtTimeField();
private AtStringCellWidget startTimeLabel = new AtStringCellWidget();
private AtStringCellWidget endTimeLabel = new AtStringCellWidget();
private AtImageCellWidget startTimeButton = new
AtImageCellWidget(AtImageList.IMAGE_LIST.CALENDAR);
private AtImageCellWidget endTimeButton = new
AtImageCellWidget(AtImageList.IMAGE_LIST.CALENDAR);
private SimpleDateFormat df = new
SimpleDateFormat(AtCommon.messageResource.getText("DATE_PATTERN"));
private java.util.Date startDate = new java.util.Date();
private java.util.Date endDate = new java.util.Date();
private static int START = 0;
private static int END = 1;
private Vector popupCollection = new Vector();
public TimeFieldDemo() {
setTitle("AtTimeField Demo");
setSize(new Dimension(250, 180));
//buttons
startTimeButton.setActionCommand("start");
startTimeButton.setFocusEnabled(true);
startTimeButton.setFont(getFont());
startTimeButton.addActionListener(this);
startTimeButton.setToolTipText("Bring up
calendar for changing start date.");
endTimeButton.setActionCommand("end");
endTimeButton.setFocusEnabled(true);
endTimeButton.setFont(getFont());
endTimeButton.addActionListener(this);
endTimeButton.setToolTipText("Bring up
calendar for changing end date.");
startTimeLabel.setText(df.format(startDate));
endTimeLabel.setText(df.format(endDate));
AtInsetsPanel top = new AtInsetsPanel(new
Insets(8, 8, 8, 8));
JPanel timePanel = new JPanel(new
GridBagLayout());
TitledBorder b1 =
BorderFactory.createTitledBorder("Select execution time");
timePanel.setBorder(b1);
AtStringCellWidget timeLabel = new
AtStringCellWidget("Time: ");
timePanel.add(timeLabel, new
GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.EAST,
GridBagConstraints.NONE, new Insets(0, 0, 0,
0), 0, 0));
timePanel.add(time, new GridBagConstraints(1,
0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets(0, 0, 0,
0), 0, 0));
JPanel dateTimePanel = new JPanel(new
GridBagLayout());
TitledBorder b2 =
BorderFactory.createTitledBorder("Select start/end date & time");
dateTimePanel.setBorder(b2);
AtStringCellWidget startLabel = new
AtStringCellWidget("Start: ");
dateTimePanel.add(startLabel, new
GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.EAST,
GridBagConstraints.NONE, new Insets(0, 0, 0,
0), 0, 0));
dateTimePanel.add(startTimeLabel, new
GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets(0, 0, 0,
0), 0, 0));
dateTimePanel.add(startTimeButton, new
GridBagConstraints(2, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets(0, 0, 0,
0), 0, 0));
AtStringCellWidget endLabel = new
AtStringCellWidget("End: ");
dateTimePanel.add(endLabel, new
GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.EAST,
GridBagConstraints.NONE, new Insets(0, 0, 0,
0), 0, 0));
dateTimePanel.add(endTimeLabel, new
GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets(0, 0, 0,
0), 0, 0));
dateTimePanel.add(endTimeButton, new
GridBagConstraints(2, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets(0, 0, 0,
0), 0, 0));
Container c = getContentPane();
c.setLayout(new BorderLayout(5, 10));
top.setLayout(new BorderLayout());
top.add(timePanel, BorderLayout.NORTH);
top.add(dateTimePanel, BorderLayout.SOUTH);
c.add(top, BorderLayout.CENTER);
AtComponentUtil.centerOnScreen(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//time.setEditable(false);
}
public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();
cleanPopups();
if (source == startTimeButton) {
JWindow popupWindow =
createCalendarPopup( (Component) evt.getSource(), START);
popupCollection.add(popupWindow);
popupWindow.show();
}else if (source == endTimeButton) {
JWindow popupWindow =
createCalendarPopup( (Component) evt.getSource(), END);
popupCollection.add(popupWindow);
popupWindow.show();
}
}
private void cleanPopups() {
for (int i=0; i<popupCollection.size(); i++)
{
JWindow window =
(JWindow) popupCollection.get(i);
if ( window != null ) {
window.dispose();
}
}
}
public JWindow createCalendarPopup(Component invoker, int fieldType) {
Calendar cal = Calendar.getInstance();
if (fieldType == START) {
cal.setTime(startDate);
} else if (fieldType == END) {
cal.setTime(endDate);
}
AtCalendar calendar = new AtCalendar(cal);
JWindow popupWindow = new JWindow(this);
Container c = popupWindow.getContentPane();
c.setLayout(new BorderLayout());
AtInsetsPanel p = new AtInsetsPanel(new
Insets(5, 5, 5, 5));
p.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
p.setLayout(new BorderLayout());
p.add(calendar, BorderLayout.CENTER);
c.add(p, BorderLayout.CENTER);
popupWindow.setSize(new Dimension(220, 250));
addFocusLostListener(popupWindow);
calendar.addActionListener(new
ActionHandler(popupWindow, calendar, fieldType));
Point scrLoc = invoker.getLocationOnScreen();
int x = scrLoc.x + invoker.getSize().width/2;
int y = scrLoc.y + invoker.getSize().height/2;
popupWindow.setLocation(x, y);
return popupWindow;
}
private class ActionHandler implements ActionListener {
JWindow popup;
AtCalendar calendar;
int fieldType;
public ActionHandler(JWindow popup, AtCalendar
calendar, int fieldType) {
this.popup = popup;
this.calendar =
calendar;
this.fieldType =
fieldType;
}
public void actionPerformed(ActionEvent evt) {
String actionCommand =
evt.getActionCommand();
AtCalendar calendar =
this.calendar;
if
(actionCommand.equals(AtCalendar.OK_ACTION_COMMAND)) {
if (fieldType == START) {
startDate = calendar.getTime();
startTimeLabel.setText(df.format(startDate));
}else if (fieldType == END) {
endDate = calendar.getTime();
endTimeLabel.setText(df.format(endDate));
}
}
popup.dispose();
}
}
private void addFocusLostListener(final JWindow window) {
window.addWindowFocusListener(new
WindowFocusListener() {
public void
windowLostFocus(WindowEvent e) {
//window.dispose();
}
public void
windowGainedFocus(WindowEvent evt) {}
});
}
}
Creating IP Address enterable fields using the AtIPAddressField class
A lot of time goes (usually more than days) for an engineer to create a simple JTextField based IP address field with some minimum data validation. To create a real good IP address enterable field it might take even longer time than a day. However, the AtIPAddressField is very nice looking component provides good UI look and feel and provides all kinds of operations to dynamically update the IP segment values. It also allows you to enable and disable the IP field so that the user can have a view only access or editable IP address field. Here is the one step process in creating an IP address enterable widget. It does every validation possible.
AtIPAddressField ipField = new AtIPAddressField("121.122.92.132");
AtIPAddressField subnetMask1 = new
AtIPAddressField(new AtIPAddressModel("100", "15", "32",
"113"));
AtIPAddressField subnetMask2 = new
AtIPAddressField( new AtIPAddressModel("", "", "",
""));
You can use a string or the AtIPAddressModel objects to hold the values of the IP field UI segments. The segments are automatically updated for any change in the AtIPAddressModel object. Alternatively, UI object can be called for setting values into the segment fields. If you want the field to be read only just call its setEditable(boolean) method.
subnetMask1.setEditable(false);
Here is an example class IPAddressFieldDemo that creates three AtIPAddressField widgets and adds them into a frame and displays the GUI.
Creating Multithreaded Progress Monitor Dialog using AtProgressDialog class
AtProgressDialog is a multitthreaded progress monitoring window can be used for any kind of applications. Because it it multithreaded developer do not have sweat days to figure out why the windows (the main window from where the progress dialog is launched or the progress window itself) are not active while the background process is in progress.
The AtProgressDialog moreover, is a special swing component that allows you to not only show the progress happening (by showing the percent completed), you can show text messages in the detail text area to see what it is doing at any time. You can cancel the progress at any time by pressing its 'Cancel" button, so that it notifies the listeners (usually main window that has launched this progress window) that the user has canceled the progress. It helps the parent application to stop the background process and to cleanup the resources used for the background process. When the porgress is completed the 'Cancel' button text is changed to show 'Close'. You can optionally, choose to select the 'Close this window when completed?' check box so that when the progress is 100 percent completed, this window will automatically destroy itself. Otherwise, by default it exists after the work is done so that the user can view the text you might have displayed in the details text display area.
Let us have a demo with the simple two steps:
1. Create an instance of AtProgressDialog (modal or non-modal)
AtProgressDialog progressWindow = new
AtProgressDialog("Progress Monitoring",
"XML processing is in progress...",
parent, false, false);
2. Listen for an event in the AtProgressDialog object.
3. Start the progress dialog.
progressWindow.start();
4. Start the data loading/processing program. The ProgressReporter class shown here is a demo class. Its report() method runs in a while loop and repeatedly updates the latest progress percentage (a number) and sets some text into to the progress bar using its setProgress(int progressPercent) and setMessage(String msg) methods after completing a loop until progress is 100%.
ProgressReporter dataLoader = new
ProgressReporter(progressWindow);
Runnable busy = new Runnable() {
public void run() {
dataLoader.report();
}
};
Thread busyThread = new Thread(busy);
busyThread.start();
Once the progress is set to 100% the AtProgressDialog automatically stops and sends a AtProgressStatusEvent to its listeners. Listeners once receives the event can take a decision whether to close the progress dialog or to keep until user close it by pressing the 'Close' button.
Finally, here is the complete example code of the ProgressDialogDemo class. It shows a GUI frame with a JButton. Waits for the user to press the 'Run Demo Progress Monitor'. If you press the button, it follows the steps mentioned above to show the AtProgressDialog and a background process called ProgressReporter. The progress reporter takes the AtProgressDialog obect to directly call its setProgress(int) and setMessage(String msg) methods for showing the progress.
//ProgressDialogDemo.java
package demo;
import com.activetree.view.AtProgressDialog;
import com.activetree.interfaces.AtProgressStatusListener;
import com.activetree.event.AtProgressStatusEvent;
import com.activetree.utils.AtComponentUtil;
import com.activetree.utils.AtLAFUtil;
import com.activetree.utils.AtDebug;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
/**
* The demo class that makes use of the AtProgressDialog class to show the
* progress and processing information of another program called ProgressReporter.
* ProgressReporter is running a while loop 100 times. Each time the execution enters
* the loop the thread just sleeps for a second before continuing for the next loop.
* Practically, you will have some valuable codes in the place of sleep to perform
* the particular operation and update the AtProgressWindow using its setMessage and
* setProgress methods.
*/
class ProgressDialogDemo extends JFrame implements ActionListener,
AtProgressStatusListener {
private ProgressReporter simulator = null;
private AtProgressDialog progressWindow = null;
private JButton runButton;
public static void main(String[] args) {
AtLAFUtil.setWindowsLookAndFeel();
ProgressDialogDemo frame = new
ProgressDialogDemo();
frame.setVisible(true);
}
public ProgressDialogDemo() {
super("AtProgressDialog Demo");
setupContentPane();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 200);
AtComponentUtil.centerOnScreen(this);
}
protected void setupContentPane() {
runButton = new JButton("Run Demo Progress
Monitor");
runButton.setMnemonic('R');
runButton.addActionListener(this);
JPanel contentPane = new JPanel();
setContentPane(contentPane);
contentPane.add(runButton,
BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent evt) {
runButton.setEnabled(false);
//create and start a progress window
final Frame parent = this;
progressWindow = new
AtProgressDialog("Progress Monitoring",
"XML processing is in progress...",
parent, false, false);
progressWindow.addProgressStatusListener(this);
progressWindow.start();
//create and start the data processing program
simulator = new
ProgressReporter(progressWindow);
Runnable busy = new Runnable() {
public void run() {
simulator.report();
}
};
Thread busyThread = new Thread(busy);
busyThread.start();
}
public void progressReported(AtProgressStatusEvent evt) {
if (evt.getStatus() ==
AtProgressStatusEvent.CANCEL) {
AtDebug.debug("Progress canceled.");
simulator.setCanceled(true);
progressWindow.dispose();
}else if (evt.getStatus() ==
AtProgressStatusEvent.SUCCESS) {
AtDebug.debug("Operation is completed successfully!");
}
runButton.setEnabled(true);
}
}
class ProgressReporter {
private AtProgressDialog monitor;
private boolean canceled = false;
public ProgressReporter(AtProgressDialog monitor) {
this.monitor = monitor;
}
public void setCanceled(boolean cancel) {
this.canceled = cancel;
}
public void report() {
int progress = 0;
while( (!canceled) && progress <
100) {
//we just want to
delay, as if we are doing something valuable.
//each while loop will
progress by 1%.
try {
Thread.currentThread().sleep(1000); //1 sec.
}catch(Exception ex) {
//
}
//Now set the progress
and show a message if applicable.
progress += 1;
monitor.setProgress(progress);
//System.out.println("progress="+progress);
if (progress == 1) {
monitor.setMessage("Parsing the XML repository for merging.");
}else if (progress ==
20) {
monitor.setMessage("Formatting the parsed data.");
}else if (progress ==
40) {
monitor.setMessage("Creating hierarchy.");
}else if (progress ==
50) {
monitor.setMessage("Verifying data relationship.");
}else if (progress ==
80) {
monitor.setMessage("Persisting into temporary cache.");
}else if (progress ==
100) {
monitor.setMessage("Data merging successfully completed!");
}
}
}
}
Creating Multi-page Wizard Dialog using AtWizardDialog class
AtWizardDialog class provides a very convenient ways of creating, displaying and user interaction with its various buttons (next, previous, ok, cancel, apply, help, finish) so that the same frame displays different components know as AtWizardPage. Important features are that it allows you to show or hide one or many of the buttons. For example, if you do not want to show the 'apply', 'help', 'ok' buttons, then simply call the hideButton(JButton buttonToHide) method. Provides an easy customizable interface to catch the events originates from these buttons by allowing to add one or more ActionListener using its addButtonActionListener() method. For example, if the user press the 'Next' button, on getting the event, you can decide which page (AtWizardPage) to show next and what task to perform before showing the next page.
The DemoWizardDialog class shows how to create and use the multi-page wizard dialog.
//DemoWizardDialog.java
package demo;
import com.activetree.swing.AtWizardPage;
import com.activetree.view.AtWizardDialog;
import com.activetree.utils.AtLAFUtil;
import com.activetree.utils.AtComponentUtil;
import javax.swing.*;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.util.Vector;
public class DemoWizardDialog implements ActionListener {
private AtWizardDialog wizard;
private AtWizardPage[] pages;
public DemoWizardDialog() {
wizard = new AtWizardDialog(new
JFrame("AtWizardDialog Demo"), "Simple Wizard Pages", true);
wizard.addButtonActionListener(this);
pages = createWizardPages();
setupContentPane();
AtComponentUtil.centerOnScreen(wizard);
}
protected void setupContentPane() {
for (int i=0; i < pages.length; i++) {
wizard.addPage(pages[i]);
}
//Hide some of the buttons
wizard.hideButton(wizard.getOkButton(), false);
wizard.hideButton(wizard.getHelpButton(),
false);
wizard.hideButton(wizard.getApplyButton(),
false);
//Disable for the fisrt page.
wizard.getPreviousButton().setEnabled(false);
wizard.getFinishButton().setEnabled(false);
wizard.showFirst();
wizard.setSize(500, 350);
}
protected AtWizardPage[] createWizardPages() {
AtWizardPage[] comps = {
new
SimpleWizardPage("Page 1", wizard.getNextButton()),
new
SimpleWizardPage("Page 2", wizard.getNextButton()),
new
SimpleWizardPage("Page 3", wizard.getNextButton()),
new
SimpleWizardPage("Page 4", wizard.getNextButton()),
new
SimpleWizardPage("Summary Page", wizard.getFinishButton())
};
return comps;
}
public void setVisible(boolean visible) {
wizard.setVisible(visible);
}
public void dispose() {
wizard.dispose();
}
public void actionPerformed(ActionEvent evt) {
String actionCmd = evt.getActionCommand();
wizard.setCursor(new
Cursor(Cursor.WAIT_CURSOR));
if (actionCmd.equals(AtWizardDialog.PREVIOUS))
{
showPrevious();
}else if
(actionCmd.equals(AtWizardDialog.NEXT)) {
showNext();
}else if
(actionCmd.equals(AtWizardDialog.FINISH)) {
wizard.setVisible(false);
wizard.dispose();
}else if
(actionCmd.equals(AtWizardDialog.CANCEL)) {
wizard.setVisible(false);
wizard.dispose();
}
wizard.setCursor(new
Cursor(Cursor.DEFAULT_CURSOR));
}
public boolean showPrevious() {
wizard.showPrevious();
wizard.getNextButton().setEnabled(true);
wizard.getFinishButton().setEnabled(false);
//If this is the first page diable the previous
button
if (wizard.getCurrentPageIndex() == 0) {
//disable the next
button becs last page.
wizard.getPreviousButton().setEnabled(false);
}else{
wizard.getPreviousButton().setEnabled(true);
}
return true;
}
public boolean showNext() {
wizard.showNext();
wizard.getPreviousButton().setEnabled(true);
//If this is the last page, disable next
button.
if (wizard.getCurrentPageIndex() ==
(wizard.getPageCount()-1)) {
//disable the next
button becs last page.
wizard.getNextButton().setEnabled(false);
wizard.getFinishButton().setEnabled(true);
}else{
wizard.getNextButton().setEnabled(true);
wizard.getFinishButton().setEnabled(false);
}
return true;
}
private class SimpleWizardPage extends AtWizardPage {
Vector listData;
JLabel nameLabel;
JLabel nameValue;
JList list;
public SimpleWizardPage(String title, JButton
defaultButton) {
super(title,
defaultButton);
}
public Container createContentPane() {
nameLabel = new
JLabel("Selected: ");
nameValue = new
JLabel(" ");
listData = new
Vector();
listData.add("David Butchar");
listData.add("Derek McDonald");
listData.add("Nancy Han");
listData.add("Cathy Thompson");
listData.add("Shilpa Roy");
list = new
JList(listData);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) {
int selIndex = list.getLeadSelectionIndex();
if (selIndex >=0) {
nameValue.setText(list.getSelectedValue().toString());
}
}
});
list.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
if (evt.getClickCount() >= 2) {
((JButton) getFocusOwner()).doClick();
}
}
});
JScrollPane listScroll
= new JScrollPane(list);
JPanel northPanel = new
JPanel(new BorderLayout());
//northPanel.add(nameLabel, BorderLayout.WEST);
northPanel.add(nameValue, BorderLayout.EAST);
JComponent container =
new JPanel(new BorderLayout(5, 5));
container.add(northPanel, BorderLayout.NORTH);
container.add(listScroll, BorderLayout.CENTER);
return container;
}
}
public static void main(String[] args) {
AtLAFUtil.setWindowsLookAndFeel();
DemoWizardDialog wizard = new
DemoWizardDialog();
wizard.setVisible(true);
}
}
Copyright © ActiveTree.com. All rights reserved.