Is this your first time here? SwingWiki is a Java Swing Developer community site with an big archive of Swing-related usenet groups and mailing lists, but also tips, tricks and articles and book reviews written by your colleagues from around the world. If you came here through a search engine and did not find what you were looking for, make sure to check the wiki table of contents.

Re: Missing events

From:"Paul Furbacher [TeamB]" [pfurbacher@masked-domain]
Sent on:Fri, 13 Apr 2007 01:02:48 -0400
In reply to:<461d4e22@newsgroups.borland.com>
Bruce Houghton wrote:

> Well, to put it as simply as I can, I created a
> JList of names(as in address book). When I click on
> a name in the JList, it won't always create an event
> even though it does cause that name to be highlighted.
>
> Now, to be more specific, I've build a POS system using
> JList's and JTables's. Touching the screen will always highlight
> the field, and a beeping sound will occure(every time), but
> it will not always trigger an event(as in below "Say Something").

Does the code below illustrate what you are attempting to do?
If so, see the JavaDoc for JList and the tutorial linked in that
JavaDoc:

http://java.sun.com/products/jfc/tsc/tech_topics/jlist_1/jlist.html


*****

package bruce.houghton.list.selection;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.BorderLayout;


public class ListEventFrame
extends JFrame {

ListModel data = new AbstractListModel() {
public int getSize() { return Byte.MAX_VALUE; }
public Object getElementAt(int index) { return "Index " + index; }
};


JPanel listPanel = new JPanel();
JScrollPane scrollPane = new JScrollPane();
JList listBox = new JList(data);
GridBagLayout gridBagLayout2 = new GridBagLayout();
JPanel buttonPanel = new JPanel();
GridBagLayout gridBagLayout3 = new GridBagLayout();
JButton quitButton = new JButton();
BorderLayout borderLayout1 = new BorderLayout();
JLabel label = new JLabel();

public ListEventFrame() {
try {
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}


private void jbInit() throws Exception {
getContentPane().setLayout(gridBagLayout2);
listPanel.setLayout(borderLayout1);
buttonPanel.setLayout(gridBagLayout3);
quitButton.setText("Quit");
quitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
quitButton_actionPerformed(actionEvent);
}
});
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
scrollPane.setPreferredSize(new Dimension(260, 250));
listBox.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent mouseEvent) {
listBox_mouseClicked(mouseEvent);
}
});
label.setText("...");
buttonPanel.add(quitButton, new GridBagConstraints(0, 0, 1, 1,
0.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
scrollPane.getViewport().add(listBox);
listPanel.add(scrollPane, java.awt.BorderLayout.CENTER);
listPanel.add(label, java.awt.BorderLayout.SOUTH);
this.getContentPane().add(buttonPanel,
new GridBagConstraints(0, 1, 1, 1, 0.0, 1.0
, GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL,
new Insets(0, 12, 11, 11), 0, 0));
this.getContentPane().add(listPanel,
new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
new Insets(12, 12, 0, 11), 0, 0));
}

public static void main(String[] args) {
ListEventFrame frame = new ListEventFrame();
frame.pack();
frame.setVisible(true);
}

public void quitButton_actionPerformed(ActionEvent actionEvent) {
System.exit(0);
}

public void listBox_mouseClicked(MouseEvent mouseEvent) {
int index = listBox.locationToIndex(mouseEvent.getPoint());
String str = (String)listBox.getModel().getElementAt(index);
System.out.println("Double clicked on Item " + index);
if (mouseEvent.getClickCount() == 2) {
JOptionPane.showMessageDialog(this, str);
return;
}
if ( mouseEvent.getClickCount() == 1 ) {
label.setText(str);
}
}

}


--


Paul Furbacher (TeamB)

Save time, search the archives:
http://info.borland.com/newsgroups/ngsearch.html

Is it in Joi Ellis's Faq-O-Matic?
http://www.visi.com/~gyles19/fom-serve/cache/1.html

Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
Found what you were looking for? If not - continue at Wiki Index

Other messages in this topic

SenderDate sentSubject
"Paul Furbacher [TeamB]" [pfurbacher@masked-domain]Wed, 11 Apr 2007 00:40:19 -0400Re: Missing events
"Bruce Houghton" [bhought@masked-domain]Fri, 6 Apr 2007 11:42:03 -0400Missing events

 
Recent changes | RSS changes | Table of contents | News Archive | Terms And Conditions | Register | The Quest For Software++| Ruby Resources

Sedo - Buy and Sell Domain Names and Websites project info: swingwiki.org Statistics for project swingwiki.org etracker� web controlling instead of log file analysis