Cory Twibell

Greenhorn
+ Follow
since Dec 06, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Cory Twibell

I've tried an ActionListener, but the JMenu doesn't receive the ActionEvent. I am trying to hide the popup menu associated with the JMenu when there is invalid text in a certain text field, because I want the user to fix the text field before moving on.
22 years ago

Originally posted by Kristof Camelbeke:
I need some help to update a Jtextfield.
when the value in the Jlist changes I want a change in the Jtextfield. Here is some code :

// this updates the Jlist (which is read from a MS-Access Database)
public void veldenListUpdate(){
DefaultListModel m = ((DefaultListModel) VeldenList.getModel());
m.removeAllElements();
try{
// create a statement handlez
Statement sqlStatement = databaseConnection.createStatement();

// create a sql-string
String sql = "SELECT * FROM VELD";
ResultSet results = sqlStatement.executeQuery(sql);

while (results.next()){
m.addElement(results.getString(1));



If I understand, you want the selected List Item to be displayed on the text field? If so, just use:
textField.setText((String)list.getSelectedValue() );
22 years ago
I have the following:


<code>
JMenu menu = new JMenu("File");
menu.addItemListener( new ItemListener()
{
public void itemStateChanged( ItemEvent e )
{
JMenu m = (JMenu)e.getItem();
if ( e.getStateChange() == ItemEvent.SELECTED )
{
if ( !valid() ) //error checks a text field
m.setPopupMenuVisible( false );
}
}
} );
</code>


The popup menu still shows. Is JMenu class overriding my call to the popup menu? Is there a different way to do this? Maybe using a different listener?
Thanks
22 years ago