Even though the combobox on the first window is disabled, it still pops up the list.The issues pointed out in JamesNC's reply are bound to be helpful. But apart from that, my own experience with JComboBox showed an odd behavior when using the attributes -textvariable => \$scalar_var, -mode => 'editable', -validate => 'match' .
(update: fixed spelling and code tags above)
I came across this when I wanted users to be able to type and/or chose from a list to set a field in a database, and also show the an existing field value from the database when the user ran a query. Funny thing was, whenever I used a query result to set the value of the textvariable, the JCombobox list menu would pop up, and wouldn't go away until there was a mouse click. Very ugly. I had to work around it by invoking the widget's "hidepopup" method every time I set the textvariable's value. The following mindless script demonstrates the problem:
It seems that the "validate => 'match'" thing is mostly responsible -- comment that out, and the popup isn't a problem. But then, you never get the popup when actually typing into the entry box either -- you don't get to see the next full choice based on what you've typed so far -- which defeats one of the big reasons for using this widget in the first place.#!/usr/bin/perl use strict; use Tk; use Tk::JComboBox; my @choice = sort qw/Foo Bar Baz Red Green Blue Orange White Black/; my $chosen; my $mw = MainWindow->new(); $mw->Label(-text => 'Pick/type a value from JComboBox:')->pack(); my $cb = $mw->JComboBox(-width => 15, -textvariable => \$chosen, -choices => \@choice, -maxrows => 5, -mode => 'editable', -validate => 'match', -relief => 'sunken', )->pack(); $mw->Label(-text => 'or just push this button:')->pack(); $mw->Button(-text => 'Make a random choice', -command => sub { my $c = int(rand( scalar @choice )); print "$choice[$c] chosen at random\n"; $chosen = $choice[$c]; # uncomment the next line to fix errant JComboBox popup: # $cb->hidePopup(); } )->pack(); MainLoop;
In reply to Re: Help with JComboBox
by graff
in thread Help with JComboBox
by ChrisR
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |