I have one JInternalframe in which there are many JRadioButton and JLabel. I want to Retrive Data from Database and display on this JRadioButton and JLabel
Since there can be any numbers of row in Database which will be fetched.
I had successfullly Fetched the data from database but not able to set it on JRadioButton and JLabel
void setData(String s1, String s2, String s3, int cnt) {
//Setting JRadioButton and JLabel Coding Part Here
}
In above function in Variable s1,s2,s3 data exist which i want to Display and in Variable cnt there is value of counter which increment on resultset.next()
Can anyone give me some tips on how to display data on JRadiobutton and JLabel
JRadioButton Variale name is something like BT1,BT2,BT3... So i tried
Since the data is dynamic the GUI should be dynamic as well.
Consider the following example:
import javax.swing.JLabel;
import javax.swing.JRadioButton;
public class GuiRow {
/** jRadioButton */
private JRadioButton jRadioButton;
/** studentIdLabel */
private JLabel studentIdLabel;
/** nameLabel */
private JLabel nameLabel;
/** courseLabel */
private JLabel courseLabel;
/**
* Constructs a new instance.
*
* #param studentIdtext
* #param nameText
* #param courseText
*/
public GuiRow(String studentIdtext, String nameText, String courseText) {
this.setjRadioButton(new JRadioButton(""));
// TODO configure radio button
this.setStudentIdLabel(new JLabel(studentIdtext));
this.setNameLabel(new JLabel(nameText));
this.setCourseLabel(new JLabel(nameText));
}
/**
* Get jRadioButton.
*
* #return jRadioButton
*/
public JRadioButton getjRadioButton() {
return this.jRadioButton;
}
/**
* Set jRadioButton.
*
* #param jRadioButton
*/
public void setjRadioButton(JRadioButton jRadioButton) {
this.jRadioButton = jRadioButton;
}
/**
* Get studentIdLabel.
*
* #return studentIdLabel
*/
public JLabel getStudentIdLabel() {
return this.studentIdLabel;
}
/**
* Set studentIdLabel.
*
* #param studentIdLabel
*/
public void setStudentIdLabel(JLabel studentIdLabel) {
this.studentIdLabel = studentIdLabel;
}
/**
* Get nameLabel.
*
* #return nameLabel
*/
public JLabel getNameLabel() {
return this.nameLabel;
}
/**
* Set nameLabel.
*
* #param nameLabel
*/
public void setNameLabel(JLabel nameLabel) {
this.nameLabel = nameLabel;
}
/**
* Get courseLabel.
*
* #return courseLabel
*/
public JLabel getCourseLabel() {
return this.courseLabel;
}
/**
* Set courseLabel.
*
* #param courseLabel
*/
public void setCourseLabel(JLabel courseLabel) {
this.courseLabel = courseLabel;
}
}
This is a simple Object to create and organize a row in your container (probably JPanel, right?)
When you are parsing the resultset you need to build a list of such objects and an add the data in there.
Here is a simple example on how to parse and display the data, which you can split into 2 or more methods and place them in the appropriate entities:
int resultsetSize = resultset.getFetchSize();
//init the list
List<GuiRow> guiRowList = new ArrayList<GuiRow>(resultsetSize);
while (resultset.next()) {
//get the column values
String id = resultset.getString("studentId");
String name = resultset.getString("studentName");
String course = resultset.getString("course");
//create the the entry
GuiRow guiRow = new GuiRow(id, name, course);
//add it to the list
guiRowList.add(guiRow);
}
//now that you have a nice list of rows add them one by one to the container
JPanel container = new JPanel(new GridLayout(resultsetSize, 4));
//further container configuration could be done here ...
for (GuiRow row : guiRowList) {
container.add(row.getjRadioButton());
container.add(row.getStudentIdLabel());
container.add(row.getNameLabel());
container.add(row.getCourseLabel());
}
Related
I am using (or trying to) use the MVC Design Pattern.
So I have a UI class that just minds its own business and a controller that, well, controlls the view.
When I register a ActionListener in the controller class it does not work. As debugging seems to show, the constructor does not even finsish after calling the constructor of a JDialog.
As describing does not make much senese, here are my classes:
This is the View:
package view;
import javax.swing.*;
import java.awt.*;
/**
* Created by Timbo on 04.05.17.
* This window will be used to authenticate library members and allow them to access staff functions
*/
public class AuthenticationWindow
{
/**
* The window that holds the authentication content
*/
private JDialog _window;
/**
* This Panel holds the fields required for the input of username and password
*/
private JPanel _textFieldPanel;
/**
* This panel will hold the buttons
*/
private JPanel _buttonPanel;
/**
* The textfield in which the username can be entered
*/
private JTextField _userName;
/**
* The field, in which the password can be entered
*/
private JPasswordField _password;
/**
* Holds a string to hint for the username
*/
private JLabel _usernameHint;
/**
* Holds a string to hint for the password
*/
private JLabel _passwordHint;
/**
* A Button that will trigger the login process
*/
private JButton _confirm;
/**
* A Button that will cancel the login process
*/
private JButton _cancel;
/**
* Creates a new Authentication Window in which a user can authenticate to get staff clearance
* #param parent The parent frame of this Window
*/
public AuthenticationWindow(Frame parent)
{
//Initialize all the components
_window = new JDialog(parent, "Please Authenticate", true);
_textFieldPanel = new JPanel(new GridLayout(2, 2));
_buttonPanel = new JPanel(new FlowLayout());
_userName = new JTextField();
_password = new JPasswordField();
_passwordHint = new JLabel("Password");
_usernameHint = new JLabel("Username");
_confirm = new JButton("Confirm");
_cancel = new JButton("Cancel");
//Assemble the textfield panel
_textFieldPanel.add(_usernameHint);
_textFieldPanel.add(_userName);
_textFieldPanel.add(_passwordHint);
_textFieldPanel.add(_password);
//Assemble the button panel
_buttonPanel.add(_cancel);
_buttonPanel.add(_confirm);
//Assemble the window
_window.setLayout(new BoxLayout(_window.getContentPane(), BoxLayout.PAGE_AXIS));
_window.add(_textFieldPanel);
_window.add(_buttonPanel);
//Configure the window
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
_window.setLocation(dim.width/2-_window.getSize().width/2, dim.height/2-_window.getSize().height/2);
_window.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
_window.pack();
//Show window
_window.setVisible(true);
}
//All the getter methods for this class
public JDialog getWindow()
{
return _window;
}
public JTextField getUsernameInput()
{
return _userName;
}
public JPasswordField getPasswordInput()
{
return _password;
}
public JButton getConfirm()
{
return _confirm;
}
public JButton getCancel()
{
return _cancel;
}
}
This is the controller in charge of the view:
package controller.start.viewController;
import view.AuthenticationWindow;
import view.ErrorScreen;
import javax.swing.*;
import java.awt.*;
import java.util.Observable;
/**
* Created by Timbo on 05.05.17.
* This is the controller class for the Authentication window. It handles updates and functionality for the view
*/
public class AuthenticationWindowController extends Observable
{
private static final char[] PASSWORD = {'T', 'o', 'r', 'v', 'a', 'l', 'd', 's'};
/**
* The view that holds the components
*/
private AuthenticationWindow _ui;
/**
* The parent frame of this view
*/
private Frame _parent;
public AuthenticationWindowController(Frame parent)
{
_ui = new AuthenticationWindow(parent);
_parent = parent;
registerListener();
}
private void registerListener()
{
_ui.getConfirm().addActionListener(e -> {checkInput();});
_ui.getCancel().addActionListener(e -> {_ui.getWindow().dispose(); System.out.println("Window disposed");});
}
/**
* This method checks the input and gives feedback to the user in case the input was wrong
* If the input was correct the user is being authenticated as staff and can access the staff view in the start window
*/
private void checkInput()
{
String username = _ui.getUsernameInput().getText();
char[] password = _ui.getPasswordInput().getPassword();
if (username.isEmpty())
{
new ErrorScreenController(_parent, ErrorScreen.USERNAME_ERROR);
}
else if (password.length == 0)
{
new ErrorScreenController(_parent, ErrorScreen.PASSWORD_ERROR);
}
else if ((username.equalsIgnoreCase("linus")) || (password.equals(PASSWORD)))
{
this.setChanged();
this.notifyObservers();
}
else
{
new ErrorScreenController(_parent, ErrorScreen.WRONG_CREDENTIALS);
}
}
}
In the constructor the actionListeners just do not fire.
If I set a breakpoint to the _parent = parent line the program only stops when I close the JDialoge that is the AuthenticationWindow.
The funny thing is I have two other classes that work in this manner. If need be I will post them here. Please let me know.
Thank you already for your help!
Your problem is that the showing of a modal dialog "stops" the current thread, until the dialog will be closed. To avoid this problem you should redesign your application as followed:
1) Remove the line _window.setVisible(true); from constructor of AuthenticationWindow
2) Create a new method in AuthenticationWindow called show
public void show() {
_window.setVisible(true);
}
3) Change the constructor of AuthenticationWindowController
public AuthenticationWindowController(Frame parent)
{
_ui = new AuthenticationWindow(parent);
_parent = parent;
registerListener();
_ui.show();
}
Some further hints:
First of all prefer Action to ActionListener. Secondary: your controller should not work with GUI widgets. So it's better to provide some high level method to your UI like setValidator() to transfer your validation functionality from controller into the UI (in this case you can create and register action directly in the UI). Also make the method to access password and login (not the fileds to input them).
im trying to build input dialog using swt.
i want to read my class properties and make the dialog window on specified order or even lexicographic order. i'll keep my class properties in linkedhahmap\treemap.
example:
public class MazeProperties {
/** Maze Name. */
private String MazeName;
/** Number of rows in maze. */
private int x;
/** The Floors. */
private int y;
/** Number of columns in maze. */
private int z;
public MazeProperties(String mazeName, int rows, int floors, int columns) {
MazeName = mazeName;
Rows = rows;
Floors = floors;
Columns = columns;
}
public class ClassInputDialog extends Dialog{
/** The shell. */
Shell shell;
/** the generic class. */
private Class<?> template;
/** Property Descriptors give me the ability to see what properties the class contains - and has generic functionalities for setters and getters for fields!. */
PropertyDescriptor[] descs;
/** I wanna have a robust connection between a property to a text box - that way upon pressing OK I could know what class property was written in it.
*
*/
HashMap<PropertyDescriptor,Text> txtMap=new LinkedHashMap<PropertyDescriptor,Text>();
//TreeMap<String,Text> txtMapOrderName=new TreeMap<String,Text>();
//Map<PropertyDescriptor, Text> txtMap = Collections.synchronizedMap(new LinkedHashMap<PropertyDescriptor, Text>());
/** The bonus demanded that this dialog will support all given classes
* but what happens when a class has an enum? a whole new story with combo-boxes and once again I wanna have a connection between the class field enum to the String that was selected in the form.
*
*/
HashMap<PropertyDescriptor,String> enumMap=new **HashMap<PropertyDescriptor,String>();**
/** This is the reference of the instance I will return.
*
*/
private Object input;
/** Ct'r for people that don't know a thing about SWT.
* #param parent - Shell
* #param template - The Class to create form to
*/
public ClassInputDialog(Shell parent,Class<?> template) {
this(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL,template);
}
/**
* Ct'r with SWT style.
*
* #param parent - Shell
* #param style - SWT style
* #param template - The Class to create form to
*/
public ClassInputDialog(Shell parent, int style,Class<?> template) {
super(parent, style);
this.template=template;
descs=PropertyUtils.getPropertyDescriptors(template);
setText("Set Properties");
}
/**
* Gets the input.
*
* #return the input
*/
public Object getInput() {
return input;
}
/**
* Sets the input.
*
* #param input the new input
*/
public void setInput(Object input) {
this.input = input;
}
/** Here the window layout is set and the main loop event happens. When window closes User's input is returned.
* #return The user's input
*/
public Object open() {
this.shell = new Shell(getParent(), getStyle());
shell.setText(getText());
createContents(shell);
shell.pack();
shell.open();
Display display = getParent().getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
//display.dispose();
return input;
}
/** Creates Window content and layout - sets Labels, Text boxes and combo boxes nicely.
* #param shell - window's parent
*/
private void createContents(final Shell shell) {
shell.setLayout(new GridLayout(2, true));
for(**PropertyDescriptor propDesc: descs**)
if(!propDesc.getName().equals("class"))
{
if(!propDesc.getPropertyType().isEnum())
{
Label label = new Label(shell, SWT.NONE);
label.setText(propDesc.getName());
GridData data = new GridData();
data.horizontalSpan = 2;
label.setLayoutData(data);
final Text text = new Text(shell, SWT.BORDER);
data = new GridData(GridData.FILL_HORIZONTAL);
data.horizontalSpan = 2;
text.setLayoutData(data);
txtMap.put(propDesc, text);
// txtMapOrderName.put(propDesc.getDisplayName(), text);
System.out.println(propDesc.getDisplayName());
}
else
{
Label label = new Label(shell, SWT.NONE);
label.setText(propDesc.getName());
GridData data = new GridData();
data.horizontalSpan = 2;
label.setLayoutData(data);
final Combo combo = new Combo(shell, SWT.DROP_DOWN);
String[] toCombo=new String[propDesc.getPropertyType().getEnumConstants().length];
for(int i=0;i<propDesc.getPropertyType().getEnumConstants().length;i++)
toCombo[i]=propDesc.getPropertyType().getEnumConstants()[i].toString();
combo.setItems(toCombo);
data = new GridData(GridData.FILL_HORIZONTAL);
data.horizontalSpan = 2;
combo.setLayoutData(data);
combo.addSelectionListener(new SelectionListener() {
#Override
public void widgetSelected(SelectionEvent arg0) {
enumMap.put(propDesc, combo.getText());
}
#Override
public void widgetDefaultSelected(SelectionEvent arg0) {
}
});
}
}
the output is not as the class properties order, it's something like
y
mazeName
x
z
If you want to map keys to values in a deterministic, predictable order, you should store them in a TreeMap, taking care that the key class implements Comparator. If it doesn't, you must implement your own Comparator and pass it as a parameter to the TreeMap constructor.
In your case, if you want PropertyDescriptor as key, you must implement your own Comparator to compare PropertyDescriptor objects.
I am using a JXComboBox as cell editor in a modified JXTable/RXTable with custom models. I am noticing a delay when starting to type inside the cell.
Edit: also, if you type more keys faster in the box, the first one you typed will not appear first in the editor.
The table:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.text.*;
import org.jdesktop.swingx.JXTable;
/**
* This is a modified version of RXTable following this thread:
* http://stackoverflow.com/questions/7365397/combining-jxtable-with-rxtable.
* The JRXTable provides some extensions to the default JTable
*
* 1) Select All editing - when a text related cell is placed in editing mode
* the text is selected. Controlled by invoking a "setSelectAll..." method.
*
* 2) reorderColumns - static convenience method for reodering table columns
*/
public class JRXTable extends JXTable {
private boolean isSelectAllForMouseEvent = false;
private boolean isSelectAllForActionEvent = false;
private boolean isSelectAllForKeyEvent = false;
//
// Constructors
//
/**
* Constructs a default
* <code>JRXTable</code> that is initialized with a default data model, a
* default column model, and a default selection model.
*/
public JRXTable() {
this(null, null, null);
}
/**
* Constructs a
* <code>JRXTable</code> that is initialized with
* <code>dm</code> as the data model, a default column model, and a default
* selection model.
*
* #param dm the data model for the table
*/
public JRXTable(TableModel dm) {
this(dm, null, null);
}
/**
* Constructs a
* <code>JRXTable</code> that is initialized with
* <code>dm</code> as the data model,
* <code>cm</code> as the column model, and a default selection model.
*
* #param dm the data model for the table
* #param cm the column model for the table
*/
public JRXTable(TableModel dm, TableColumnModel cm) {
this(dm, cm, null);
}
/**
* Constructs a
* <code>JRXTable</code> that is initialized with
* <code>dm</code> as the data model,
* <code>cm</code> as the column model, and
* <code>sm</code> as the selection model. If any of the parameters are
* <code>null</code> this method will initialize the table with the
* corresponding default model. The
* <code>autoCreateColumnsFromModel</code> flag is set to false if
* <code>cm</code> is non-null, otherwise it is set to true and the column
* model is populated with suitable
* <code>TableColumns</code> for the columns in
* <code>dm</code>.
*
* #param dm the data model for the table
* #param cm the column model for the table
* #param sm the row selection model for the table
*/
public JRXTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm) {
super(dm, cm, sm);
}
/**
* Constructs a
* <code>JRXTable</code> with
* <code>numRows</code> and
* <code>numColumns</code> of empty cells using
* <code>DefaultTableModel</code>. The columns will have names of the form
* "A", "B", "C", etc.
*
* #param numRows the number of rows the table holds
* #param numColumns the number of columns the table holds
*/
public JRXTable(int numRows, int numColumns) {
this(new DefaultTableModel(numRows, numColumns));
}
/**
* Constructs a
* <code>JRXTable</code> to display the values in the
* <code>Vector</code> of
* <code>Vectors</code>,
* <code>rowData</code>, with column names,
* <code>columnNames</code>. The
* <code>Vectors</code> contained in
* <code>rowData</code> should contain the values for that row. In other
* words, the value of the cell at row 1, column 5 can be obtained with the
* following code:
* <p>
* <pre>((Vector)rowData.elementAt(1)).elementAt(5);</pre>
* <p>
*
* #param rowData the data for the new table
* #param columnNames names of each column
*/
public JRXTable(Vector rowData, Vector columnNames) {
this(new DefaultTableModel(rowData, columnNames));
}
/**
* Constructs a
* <code>JRXTable</code> to display the values in the two dimensional array,
* <code>rowData</code>, with column names,
* <code>columnNames</code>.
* <code>rowData</code> is an array of rows, so the value of the cell at row
* 1, column 5 can be obtained with the following code:
* <p>
* <pre> rowData[1][5]; </pre>
* <p>
* All rows must be of the same length as
* <code>columnNames</code>.
* <p>
*
* #param rowData the data for the new table
* #param columnNames names of each column
*/
public JRXTable(final Object[][] rowData, final Object[] columnNames) {
super(rowData, columnNames);
}
//
// Overridden methods
//
/*
* Override to provide Select All editing functionality
*/
#Override
public boolean editCellAt(int row, int column, EventObject e) {
boolean result = super.editCellAt(row, column, e);
// my editing
//
// if (e instanceof KeyEvent && isSelectAllForKeyEvent) {
// KeyEvent keyEvent = (KeyEvent) e;
// Character keyChar = keyEvent.getKeyChar();
// if (keyChar == KeyEvent.VK_ESCAPE) {
// return result;
// }
// }
// my editing
if (isSelectAllForMouseEvent
|| isSelectAllForActionEvent
|| isSelectAllForKeyEvent) {
selectAll(e);
}
return result;
}
/*
* Select the text when editing on a text related cell is started
*/
private void selectAll(EventObject e) {
final Component editor = getEditorComponent();
// add suport for the text editor from a ComboBox
// move to editCellAt method?
if (getEditorComponent() instanceof JComboBox) {
final JComboBox combo = (JComboBox) getEditorComponent();
ComboBoxEditor comboEditor = combo.getEditor();
final JTextField comboTextField = (JTextField) comboEditor.getEditorComponent();
// comboEditor.selectAll();
if (e instanceof KeyEvent && isSelectAllForKeyEvent) {
KeyEvent keyEvent = (KeyEvent) e;
final Character keyChar = keyEvent.getKeyChar();
if (keyChar == KeyEvent.VK_ESCAPE) {
System.out.println("escape");
// combo.getFocusCycleRootAncestor().requestFocus();
// combo.transferFocus();
} else {
comboEditor.selectAll();
comboTextField.setText(comboTextField.getText());
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
// set null value if the Delete key is pressed
if (keyChar == KeyEvent.VK_DELETE) {
combo.setSelectedItem(null);
comboTextField.setText(null);
} else {
comboTextField.selectAll();
// comboTextField.setText("");
}
}
});
}
}
return;
}
if (editor == null
|| !(editor instanceof JTextComponent
|| editor instanceof JFormattedTextField)) {
return;
}
if (e == null) {
((JTextComponent) editor).selectAll();
return;
}
// Typing in the cell was used to activate the editor
if (e instanceof KeyEvent && isSelectAllForKeyEvent) {
((JTextComponent) editor).selectAll();
return;
}
// If the cell we are dealing with is a JFormattedTextField
// force to commit, and invoke selectall
if (editor instanceof JFormattedTextField) {
invokeSelectAll((JFormattedTextField) editor);
return;
}
// F2 was used to activate the editor
if (e instanceof ActionEvent && isSelectAllForActionEvent) {
((JTextComponent) editor).selectAll();
return;
}
// A mouse click was used to activate the editor.
// Generally this is a double click and the second mouse click is
// passed to the editor which would remove the text selection unless
// we use the invokeLater()
if (e instanceof MouseEvent && isSelectAllForMouseEvent) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
((JTextComponent) editor).selectAll();
}
});
}
}
private void invokeSelectAll(final JFormattedTextField editor) {
// old trick: force to commit, and invoke selectall
editor.setText(editor.getText());
SwingUtilities.invokeLater(new Runnable() {
public void run() {
editor.selectAll();
}
});
}
//
// Newly added methods
//
/*
* Sets the Select All property for for all event types
*/
public void setSelectAllForEdit(boolean isSelectAllForEdit) {
setSelectAllForMouseEvent(isSelectAllForEdit);
setSelectAllForActionEvent(isSelectAllForEdit);
setSelectAllForKeyEvent(isSelectAllForEdit);
}
/*
* Set the Select All property when editing is invoked by the mouse
*/
public void setSelectAllForMouseEvent(boolean isSelectAllForMouseEvent) {
this.isSelectAllForMouseEvent = isSelectAllForMouseEvent;
}
/*
* Set the Select All property when editing is invoked by the "F2" key
*/
public void setSelectAllForActionEvent(boolean isSelectAllForActionEvent) {
this.isSelectAllForActionEvent = isSelectAllForActionEvent;
}
/*
* Set the Select All property when editing is invoked by
* typing directly into the cell
*/
public void setSelectAllForKeyEvent(boolean isSelectAllForKeyEvent) {
this.isSelectAllForKeyEvent = isSelectAllForKeyEvent;
}
//
// Static, convenience methods
//
/**
* Convenience method to order the table columns of a table. The columns are
* ordered based on the column names specified in the array. If the column
* name is not found then no column is moved. This means you can specify a
* null value to preserve the current order of a given column.
*
* #param table the table containing the columns to be sorted
* #param columnNames an array containing the column names in the order they
* should be displayed
*/
public static void reorderColumns(JTable table, Object... columnNames) {
TableColumnModel model = table.getColumnModel();
for (int newIndex = 0; newIndex < columnNames.length; newIndex++) {
try {
Object columnName = columnNames[newIndex];
int index = model.getColumnIndex(columnName);
model.moveColumn(index, newIndex);
} catch (IllegalArgumentException e) {
}
}
}
} // End of Class JRXTable
The test class:
import java.text.FieldPosition;
import java.text.Format;
import java.text.ParsePosition;
import java.util.HashMap;
import javax.swing.ComboBoxEditor;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.plaf.basic.BasicComboBoxEditor;
import javax.swing.table.DefaultTableModel;
import org.jdesktop.swingx.JXComboBox;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
import org.jdesktop.swingx.autocomplete.ComboBoxCellEditor;
import org.jdesktop.swingx.autocomplete.ObjectToStringConverter;
import org.jdesktop.swingx.renderer.DefaultListRenderer;
import org.jdesktop.swingx.renderer.DefaultTableRenderer;
import org.jdesktop.swingx.renderer.StringValue;
public class TestSwingXComboCellEditor {
public static void main(String[] args) {
TestSwingXComboCellEditor test = new TestSwingXComboCellEditor();
test.go();
}
public void go() {
//create the frame
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// create and add a tabbed pane to the frame
JTabbedPane tabbedPane = new JTabbedPane();
frame.getContentPane().add(tabbedPane);
//create a table and add it to a scroll pane in a new tab
JRXTable table = new JRXTable();
table.setModel(new DefaultTableModel(new Object[]{"A", "B"}, 5));
table.setSelectAllForEdit(true);
JScrollPane scrollPane = new JScrollPane(table);
tabbedPane.addTab("test", scrollPane);
// create a simple JComboBox and set is as table cell editor on column A
UserRepository rep = new UserRepository();
UserInfo[] comboElements = rep.getAllUsers();
DefaultComboBoxModel model = new DefaultComboBoxModel(comboElements);
JXComboBox comboBox = new JXComboBox(model);
StringValue stringValue = new StringValue() {
public String getString(Object value) {
if (value instanceof UserInfo) {
UserInfo userInfo = (UserInfo) value;
return userInfo.getFirstName();
} else {
return "";
}
}
};
ComboBoxCellEditor cellEditor = new ComboBoxCellEditor(comboBox);
comboBox.setRenderer(new DefaultListRenderer(stringValue));
comboBox.setEditable(true);
AutoCompleteDecorator.decorate(comboBox, new ObjectToStringConverter() {
#Override
public String getPreferredStringForItem(Object item) {
if (item instanceof UserInfo) {
return ((UserInfo) item).getFirstName();
} else {
return null;
}
}
});
table.getColumn("A").setCellEditor(cellEditor);
table.getColumn("A").setCellRenderer(new DefaultTableRenderer(stringValue));
// pack and show frame
frame.pack();
frame.setVisible(true);
}
public class UserInfo {
private String firstName;
private String lastName;
public UserInfo(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
}
public class UserRepository {
UserInfo[] comboElements;
HashMap<String, UserInfo> objectsMap;
public UserRepository() {
comboElements = new UserInfo[5];
comboElements[0] = new UserInfo("John", "Doe");
comboElements[1] = new UserInfo("Betty", "Doe");
comboElements[2] = new UserInfo("Elenor", "Smith");
comboElements[3] = new UserInfo("Helen", "Kelly");
comboElements[4] = new UserInfo("Joe", "Black");
objectsMap = new HashMap<>();
for (int i = 0; i < 5; i++) {
objectsMap.put(comboElements[i].getFirstName(), comboElements[i]);
}
}
public UserInfo getUserInfo(String name) {
return objectsMap.get(name);
}
public UserInfo[] getAllUsers() {
return comboElements;
}
}
}
This is probably an elementary question. However, I have completed reading the 12th Chapter of Java Programming for the Absolute Beginner and have approached the Challenges section. I cannot quite get the progam to display a labeled button with the extended class.
The specification states:
Extend the JPRButton3D class to create a button that displays a label just like
the AWT Button class you're so familiar with by now. As an extra test, override
the isFocusable() method so that your button class can be traversed and make sure you
paint some special graphic to make it obvious when your button has focus.
How can I edit my code of LabelButton3D and LabelButton3DTest to accomplish this task?
An answer to this specification can potentially aid many new Java programmers in extending their own classes.
Thank you very much for your time and cooperation reagrding this matter.
HERE IS THE CODE FOR JPRButton3D:
package jpr.lightweight;
import java.awt.*;
import java.awt.event.*;
/**
* A lightweight 3D Button class that fires actions when clicked.
* When it is enabled it appears {#link #RAISED RAISED}, when
* it is pressed it appears {#link #SUNK SUNK}, and when it is
* not enabled, it appears {#link #FLAT FLAT}.
*/
public class JPRButton3D extends JPRRectComponent3D {
private boolean pressed;
/**
* This <code>JPRButton3D</code>'s <code>ActionListener</code>.
*/
protected ActionListener actionListener;
private String actionCommand;
/**
* Constructs a new <code>JPRButton3D</code> with minimum size
*/
public JPRButton3D() {
this(ABSOLUTE_MIN_WIDTH, ABSOLUTE_MIN_HEIGHT, 1);
}
/**
* Constructs a new <code>JPRButton3D</code> with the given dimensions.
* #param wide the width
* #param high the height
*/
public JPRButton3D(int wide, int high) {
this(wide, high, 1);
}
/**
* Constructs a new <code>JPRButton3D</code> with the given dimensions
* and border magnitude.
* #param wide the width
* #param high the height
* #param border_magnitude the border's magnitude
*/
public JPRButton3D(int wide, int high, int border_magnitude) {
super(wide, high, RAISED, border_magnitude);
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
}
public void processMouseEvent(MouseEvent e) {
if (isEnabled() & e.getModifiers() == MouseEvent.BUTTON1_MASK) {
switch(e.getID()) {
case MouseEvent.MOUSE_PRESSED:
pressed = true;
current_appearance = SUNK;
repaint();
break;
case MouseEvent.MOUSE_EXITED:
if (pressed) {
pressed = false;
current_appearance = RAISED;
repaint();
}
break;
case MouseEvent.MOUSE_RELEASED:
if (pressed) {
current_appearance = RAISED;
repaint();
if (actionListener != null) {
actionListener.actionPerformed(new ActionEvent(this,
ActionEvent.ACTION_PERFORMED, actionCommand,
e.getModifiers()));
}
}
break;
}
}
super.processMouseEvent(e);
}
/**
* Adds the specified <code>ActionListener</code>
* #param listener <code>ActionListener</code> to add
*/
public void addActionListener(ActionListener listener) {
actionListener = AWTEventMulticaster.add(actionListener, listener);
}
/**
* Removes the specified <code>ActionListener</code>
* #param listener <code>ActionListener</code> to remove
*/
public void removeActionListener(ActionListener listener) {
actionListener = AWTEventMulticaster.remove(actionListener,
listener);
}
/**
* Sets the action command associated with action events.
* #param command The action command.
*/
public void setActionCommand(String command) {
actionCommand = command;
}
/**
* Gets the action command associated with action events.
* #return the action command
*/
public String getActionCommand() {
return actionCommand;
}
/**
* Enables or disables this <code>JPRButton3D</code>.
* #param b <code>true</code> to enable, <code>false</code> to disable
*/
public void setEnabled(boolean b) {
if (b) current_appearance = RAISED;
else current_appearance = FLAT;
repaint();
super.setEnabled(b);
}
}
HERE IS MY CODE FOR LabelButton3DTest (to extend JPRButton3D):
import java.awt.*;
import java.awt.event.*;
import jpr.lightweight.JPRButton3D;
public class LabelButton3DTest extends GUIFrame {
LabelButton3D[] b;
String s;
public LabelButton3DTest() {
super("LabelButton3D Test");
setLayout(new FlowLayout());
b = new LabelButton3D[1];
b[0] = new LabelButton3D("Favorite Button");
b[0] = new LabelButton3D(75, 35, 1);
add(b[0]);
pack();
setVisible(true);
}
public static void main(String args[]) {
new LabelButton3DTest();
}
}
HERE IS MY CODE FOR LabelButton3D:
public class LabelButton3D extends JPRButton3D {
public LabelButton3D(String label) {
}
public LabelButton3D(int wide, int high, int border_magnitude) {
super(wide, high, border_magnitude);
}
}
Hi, I am trying to show more detailed information after a user clicks on the message balloon tooltip.
However, I can't find how to capture that event.
Is this possible to do?
1) Is possible to listening MouseClickEvents by add ActionListener to the TrayIcon, then Message body listening for MouseClicked
2) (not asked directly) but I can't to give you an answer listening if message was closed by close button, and Message gone away from screen same way, but without catch any event(s)
3) looks like as this Java TrayIcon message close button should be only one solutions, because API doesn't implements another methods,
import java.awt.*;
import java.awt.event.*;
public class FullTray {
private static class ShowMessageListener implements ActionListener {
private TrayIcon trayIcon;
private String title;
private String message;
private TrayIcon.MessageType messageType;
ShowMessageListener(TrayIcon trayIcon, String title, String message, TrayIcon.MessageType messageType) {
this.trayIcon = trayIcon;
this.title = title;
this.message = message;
this.messageType = messageType;
}
public void actionPerformed(ActionEvent e) {
trayIcon.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Message Clicked");
}
});
trayIcon.displayMessage(title, message, messageType);
}
}
public static void main(String args[]) {
Runnable runner = new Runnable() {
public void run() {
if (SystemTray.isSupported()) {
final SystemTray tray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().getImage("gifIcon.gif");
PopupMenu popup = new PopupMenu();
final TrayIcon trayIcon = new TrayIcon(image, "The Tip Text", popup);
MenuItem item = new MenuItem("Error");
item.addActionListener(new ShowMessageListener(trayIcon, "Error Title", "Error", TrayIcon.MessageType.ERROR));
popup.add(item);
item = new MenuItem("Warning");
item.addActionListener(new ShowMessageListener(trayIcon, "Warning Title", "Warning", TrayIcon.MessageType.WARNING));
popup.add(item);
item = new MenuItem("Info");
item.addActionListener(new ShowMessageListener(trayIcon, "Info Title", "Info", TrayIcon.MessageType.INFO));
popup.add(item);
item = new MenuItem("None");
item.addActionListener(new ShowMessageListener(trayIcon, "None Title", "None", TrayIcon.MessageType.NONE));
popup.add(item);
item = new MenuItem("Close");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tray.remove(trayIcon);
}
});
popup.add(item);
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println("Can't add to tray");
}
} else {
System.err.println("Tray unavailable");
}
}
};
EventQueue.invokeLater(runner);
}
private FullTray() {
}
}
Even though this topic isn't exactly recent, I figured I'd share my solution since this kind of thing doesn't really change.
How To Use
To use this code, just create the 1 public class and the 2 public interfaces.
Now create an instance of the CustomTrayIcon class and call the addToSystemTray() method, once you're done initializing it.
Anytime you want to show a notification bubble, call the showBubbleNotification(...) method.
To remove this tray icon, just call the removeFromSystemTray() method.
CustomTrayIcon
This class is the base which does all of the heavy lifting.
package com.samples;
import java.awt.AWTException;
import java.awt.Image;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/**
* This class can be used to create an icon in the {#link SystemTray}, providing
* the current operating system supports the {#link SystemTray}. <br />
* <br />
* <b><u>Userful Methods</u>:</b>
* <ul>
* <li>
* Use the {#link CustomTrayIcon#addToSystemTray() addToSystemTray()} method to
* add this {#link CustomTrayIcon} to the {#link SystemTray}. <br />
* </li>
* <li>
* Use the {#link CustomTrayIcon#removeFromSystemTray() removeFromSystemTray()}
* method to remove this {#link CustomTrayIcon} from the {#link SystemTray}. <br />
* </li>
* <li>
* Use the
* {#link CustomTrayIcon#showBubbleNotification(String, String, MessageType, CustomTrayIconNotificationBubbleClickEvent)
* showBubbleNotification(String, String, MessageType,
* CustomTrayIconNotificationBubbleClickEvent)} method to show a bubble notification to
* the user. <br />
* </li>
* <li>
* Use the {#link CustomTrayIcon#setClickDetectionDelay_override(int)
* setClickDetectionDelay_override(int)} method to override the default delay to
* be used when detecting if a user performed a single/double/triple click.</li>
* </ul>
*
* #author Matthew Weiler
* */
public abstract class CustomTrayIcon extends TrayIcon implements CustomTrayIconMouseInterface
{
/* PRIVATE CONSTANTS */
/**
* This will be used as the millisecond delay between clicks to detect
* single or double clicks. <br />
* <br />
* <b><u>Default Value</u>:</b> 300
* */
private static final int DEFAULT_CLICK_DETECTION_DELAY = 300;
/**
* This will be used to ensure that we can synchronize the click counter
* changes.
* */
private static final Object clickLock = new Object();
/* PRIVATE VARIABLES */
/**
* This will store the override value to be used in-place of the
* {#link CustomTrayIcon#DEFAULT_CLICK_DETECTION_DELAY CLICK_DETECTION_DELAY}
* default value.
*
* #see CustomTrayIcon#DEFAULT_CLICK_DETECTION_DELAY
* */
private int clickDetectionDelay_override = -1;
/**
* This will store the {#link CustomTrayIconNotificationBubbleClickEvent} which
* should be executed the next time that an {#link ActionEvent} is fired by
* the user clicking a notification bubble.
* */
private CustomTrayIconNotificationBubbleClickEvent newBubbleAction = null;
/**
* This will be used to keep track of which click was responsible for the
* current click timer.
* */
private long clickOwnerIndex = 0L;
/**
* This will be used to keep track of how many clicks occurred in the
* current click detection cycle.
* */
private int clickCounter = 0;
/* CONSTRUCTORS */
/**
* This will create a new instance of a {#link CustomTrayIcon}.
*
* #param image
* The {#link Image} to display as the icon in the notification
* tray.
* */
public CustomTrayIcon(final Image image)
{
super(image);
this.postCreateTasks();
}
/**
* This will create a new instance of a {#link CustomTrayIcon}.
*
* #param image
* The {#link Image} to display as the icon in the notification
* tray.
* #param tooltip
* The string to be used as tooltip text; if the value is null no
* tooltip is shown.
* */
public CustomTrayIcon(final Image image, final String tooltip)
{
super(image, tooltip);
this.postCreateTasks();
}
/**
* This will create a new {#link CustomTrayIcon}. <br />
* The {#link CustomTrayIcon}
* */
public CustomTrayIcon(final Image image, final String tooltip, final PopupMenu popup)
{
super(image, tooltip, popup);
this.postCreateTasks();
}
/* PUBLIC METHODS */
/**
* This will determine if the current operating system supports
* {#link SystemTray}.
*
* #see SystemTray#isSupported()
*
* #return <code>true</code> if the current operating system supports
* {#link SystemTray}; <code>false</code> otherwise.
* */
public static boolean isSystemTraySupported()
{
return SystemTray.isSupported();
}
/**
* This method will add this {#link CustomTrayIcon} to {#link SystemTray} . <br />
* <br />
* <i>this method may return <code>false</code> if the current operating
* system does not have or support a {#link SystemTray}</i>
*
* #return <code>true</code> if this {#link CustomTrayIcon} was added;
* <code>false</code> otherwise.
* */
public boolean addToSystemTray()
{
// Ensure that the current operating system supports
// the SystemTray.
if (CustomTrayIcon.isSystemTraySupported())
{
try
{
// Add this CustomTrayIcon to the SystemTray.
SystemTray.getSystemTray().add(this);
return true;
}
catch (AWTException e)
{
// ignore
}
}
return false;
}
/**
* This method will remove this {#link CustomTrayIcon} from the
* {#link SystemTray}.
* */
public void removeFromSystemTray()
{
SystemTray.getSystemTray().remove(this);
}
#Override
public void displayMessage(final String caption, final String text, final MessageType messageType)
{
this.newBubbleAction = null;
super.displayMessage(caption, text, messageType);
}
/**
* This method will show a bubble notification near the
* {#link CustomTrayIcon}.
*
* #see TrayIcon#displayMessage(String, String, MessageType)
*
* #param title
* The title to be displayed in the bubble notification.
* #param message
* The message to be displayed in the bubble notification.
* #param messageType
* The type of {#link MessageType} which will denote the style of
* the bubble notification.
* #param actionOnClick
* The {#link CustomTrayIconNotificationBubbleClickEvent} which should be
* fired when the user clicks the bubble notification.
*
* #throws NullPointerException
* If both caption and text are <code>null</code>.
* */
public void displayMessage(final String title, final String message, final MessageType messageType, final CustomTrayIconNotificationBubbleClickEvent actionOnClick)
{
this.showBubbleNotification(title, message, messageType, actionOnClick);
}
/**
* This method will show a bubble notification near the
* {#link CustomTrayIcon}.
*
* #see TrayIcon#displayMessage(String, String, MessageType)
*
* #param title
* The title to be displayed in the bubble notification.
* #param message
* The message to be displayed in the bubble notification.
* #param messageType
* The type of {#link MessageType} which will denote the style of
* the bubble notification.
*
* #throws NullPointerException
* If both caption and text are <code>null</code>.
* */
public void showBubbleNotification(final String title, final String message, final MessageType messageType)
{
this.showBubbleNotification(title, message, messageType, null);
}
/**
* This method will show a bubble notification near the
* {#link CustomTrayIcon}.
*
* #see TrayIcon#displayMessage(String, String, MessageType)
*
* #param title
* The title to be displayed in the bubble notification.
* #param message
* The message to be displayed in the bubble notification.
* #param messageType
* The type of {#link MessageType} which will denote the style of
* the bubble notification.
* #param actionOnClick
* The {#link CustomTrayIconNotificationBubbleClickEvent} which should be
* fired when the user clicks the bubble notification.
*
* #throws NullPointerException
* If both caption and text are <code>null</code>.
* */
public void showBubbleNotification(final String title, final String message, final MessageType messageType, final CustomTrayIconNotificationBubbleClickEvent actionOnClick)
{
this.newBubbleAction = actionOnClick;
super.displayMessage(title, message, messageType);
}
/* GETTERS & SETTERS */
/**
* This will get the override value to be used in-place of the
* {#link CustomTrayIcon#DEFAULT_CLICK_DETECTION_DELAY CLICK_DETECTION_DELAY}
* default value.
*
* #see CustomTrayIcon#DEFAULT_CLICK_DETECTION_DELAY
*
* #return The override value to be used in-place of the
* {#link CustomTrayIcon#DEFAULT_CLICK_DETECTION_DELAY
* CLICK_DETECTION_DELAY} default value.
* */
public int getClickDetectionDelay_override()
{
return this.clickDetectionDelay_override;
}
/**
* This will set the override value to be used in-place of the
* {#link CustomTrayIcon#DEFAULT_CLICK_DETECTION_DELAY CLICK_DETECTION_DELAY}
* default value.
*
* #see CustomTrayIcon#DEFAULT_CLICK_DETECTION_DELAY
*
* #param clickDetectionDelay_override
* The override value to be used in-place of the
* {#link CustomTrayIcon#DEFAULT_CLICK_DETECTION_DELAY
* CLICK_DETECTION_DELAY} default value.
* */
public void setClickDetectionDelay_override(final int clickDetectionDelay_override)
{
this.clickDetectionDelay_override = clickDetectionDelay_override;
}
/* PRIVATE METHODS */
/**
* This method will return the delay to have between each click when
* determining if the user performed a single/double/triple click.
*
* #return The delay to have between each click when determining if the user
* performed a single/double/triple click.
* */
private int getClickDetectionDelay()
{
if (this.clickDetectionDelay_override > 0)
{
return this.clickDetectionDelay_override;
}
return CustomTrayIcon.DEFAULT_CLICK_DETECTION_DELAY;
}
/**
* This method will be executed as the constructors last task. <br />
* <br />
* <i>this method will set some attributes on this {#link CustomTrayIcon} and
* apply the appropriate listeners</i>
* */
private void postCreateTasks()
{
this.setImageAutoSize(true);
this.applyCustomListeners();
}
/**
* This will apply the various listeners to this {#link CustomTrayIcon}
* object.
* */
private void applyCustomListeners()
{
// Add an ActionListener which will fire when the user
// clicks a bubble notification.
this.addActionListener(new ActionListener()
{
#Override
public void actionPerformed(ActionEvent e)
{
if (CustomTrayIcon.this.newBubbleAction != null)
{
CustomTrayIcon.this.newBubbleAction.button1_click();
CustomTrayIcon.this.newBubbleAction = null;
}
}
});
// Add a MouseListener on this CustomTrayIcon which will
// fire when the user interacts with this CustomTrayIcon
// using their mouse.
this.addMouseListener(new MouseListener()
{
#Override
public void mouseReleased(MouseEvent arg0)
{
// NOT SUPPORTED BY TrayIcon
}
#Override
public void mousePressed(MouseEvent arg0)
{
// NOT SUPPORTED BY TrayIcon
}
#Override
public void mouseExited(MouseEvent arg0)
{
}
#Override
public void mouseEntered(MouseEvent arg0)
{
}
#Override
public void mouseClicked(MouseEvent arg0)
{
// Clear the bubble notification action as any open
// bubbles should be popped/closed when this interaction
// occurs.
CustomTrayIcon.this.newBubbleAction = null;
// If this MouseEvent was triggered by mouse button 1
// being clicked... then continue.
if (arg0.getButton() == MouseEvent.BUTTON1)
{
long tmp_clickOwnerIndex = 0L;
// Ensure that only one thread can modify the click owner index
// at any given time.
synchronized (CustomTrayIcon.clickLock)
{
// Increase the click owner index so that only the very
// last click can fire an event.
CustomTrayIcon.this.clickOwnerIndex++;
// Store the current value of the click owner index
tmp_clickOwnerIndex = CustomTrayIcon.this.clickOwnerIndex;
}
// Extract the click owner index, which was obtained in a
// thread-safe way, into a final variable so we can access it
// below.
final long tmp_clickOwnerIndex_final = tmp_clickOwnerIndex;
// Launch a new Thread which will sleep for a pre-determined
// period of time to catch the delay of a double/triple click.
(new Thread()
{
int tmp_clickCounter = 0;
public void run()
{
// Ensure that only one thread can modify the click
// counter at any given time.
synchronized (CustomTrayIcon.clickLock)
{
// Increase the number of active clicks that occurred
// during the current detection cycle.
CustomTrayIcon.this.clickCounter++;
// Extract the total number of active clicks that occurred
// during the current detection cycle up to this point.
tmp_clickCounter = CustomTrayIcon.this.clickCounter;
}
try
{
// Sleep for the pre-determined multiple click detection
// time.
// This ensures that we give the use enough time to
// actually perform multiple clicks.
Thread.sleep(CustomTrayIcon.this.getClickDetectionDelay());
}
catch (InterruptedException e)
{
// ignore
}
// Ensure that only one thread can modify the click owner index
// at any given time.
synchronized (CustomTrayIcon.clickLock)
{
// If this click was the last click since the appropriate
// delay, then it's clear that this click should be
// processed.
if (CustomTrayIcon.this.clickOwnerIndex == tmp_clickOwnerIndex_final)
{
// If only one click occurred during the allocated delayed
// time, then fire a button 1 click.
if (tmp_clickCounter == 1)
{
CustomTrayIcon.this.button1_click();
}
// If two clicks occurred during the allocated delayed
// time, then fire a button 2 click.
else if (tmp_clickCounter == 2)
{
CustomTrayIcon.this.button1_doubleClick();
}
// If three clicks occurred during the allocated delayed
// time, then fire a button 3 click.
else if (tmp_clickCounter == 3)
{
CustomTrayIcon.this.button1_tripleClick();
}
}
// Decrease the click owner index which will reset the
// click stack.
CustomTrayIcon.this.clickCounter--;
}
}
}).start();
}
// If this MouseEvent was triggered by mouse button 2
// being clicked... then continue.
else if (arg0.getButton() == MouseEvent.BUTTON2)
{
// Ensure that only one thread can modify the click owner index
// at any given time.
synchronized (CustomTrayIcon.clickLock)
{
// Increase the click owner index so that only the very
// last click can fire an event.
CustomTrayIcon.this.clickOwnerIndex++;
}
CustomTrayIcon.this.button2_click();
}
// If this MouseEvent was triggered by mouse button 3
// being clicked... then continue.
else if (arg0.getButton() == MouseEvent.BUTTON3)
{
// Ensure that only one thread can modify the click owner index
// at any given time.
synchronized (CustomTrayIcon.clickLock)
{
// Increase the click owner index so that only the very
// last click can fire an event.
CustomTrayIcon.this.clickOwnerIndex++;
}
CustomTrayIcon.this.button3_click();
}
}
});
}
}
CustomTrayIconMouseInterface
This interface is used to externalize various user interactions via the mouse.
package com.samples;
import javax.swing.Popup;
/**
* This interface contains several methods which can be fired when a user
* interacts with the {#link CustomTrayIcon} using their mouse.
*
* #author Matthew Weiler
* */
public interface CustomTrayIconMouseInterface
{
/**
* This method will be fired when the user clicks, with mouse button 1, this
* {#link CustomTrayIcon}.
* */
public void button1_click();
/**
* This method will be fired when the user double-clicks, with mouse button
* 1, this {#link CustomTrayIcon}.
* */
public void button1_doubleClick();
/**
* This method will be fired when the user triple-clicks, with mouse button
* 1, this {#link CustomTrayIcon}.
* */
public void button1_tripleClick();
/**
* This method will be fired when the user clicks, with mouse button 2, this
* {#link CustomTrayIcon}.
* */
public void button2_click();
/**
* This method will be fired when the user clicks, with mouse button 3, this
* {#link CustomTrayIcon}. <br />
* <br />
* <i>if a {#link Popup} menu is assigned to this {#link CustomTrayIcon}, it
* will still popup regardless of any actions taken by this method</i>
* */
public void button3_click();
}
CustomTrayIconNotificationBubbleClickEvent
This interface is used to externalize the interaction with the notification bubble.
package com.samples;
/**
* This interface contains several methods which can be fired when a user
* interacts with a bubble notification using their mouse.
*
* #author Matthew Weiler
* */
public interface CustomTrayIconNotificationBubbleClickEvent
{
/**
* This method will be fired when the user clicks, with mouse button 1, this
* bubble notification.
* */
public void button1_click();
}