my $id = $sel || (@ids && $ids[0]) || ''; my $IDText = $dlg->add ( 'JComboBox', -options => \@ids, -mode => 'readonly', -selectcommand => [\&changeEditPlayer, \$id], -validate => 'match', -textvariable => \$id, ); # $IDText->configure (-options => \@ids); $IDText->setSelected ($id); return if $dlg->Show (-global) ne 'OK'; }
Another way I sometimes use, is to set the -textvariable directly to the first array element. This works, but I really havn't tested it, for glitches. :-)
#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::DialogBox; use Tk::JComboBox; my $main = MainWindow->new (-title => "Test JComboBox"); EditPlayers ($main); sub EditPlayers { my ($main, $sel) = @_; my @ids = qw(Fred Joe Bob); my $dlg = $main->DialogBox (-title => "Member Information", -butto +ns => ["OK", "Cancel"]); my $IDText = $dlg->add ( 'JComboBox', -options => \@ids, -mode => 'readonly', -selectcommand => [\&changeEditPlayer, \$ids[0]], -validate => 'match', -textvariable => \$ids[0], ); $IDText->form (-left => '%0', -right => '%100', -top => '%0'); # $IDText->setSelected ($ids[1]); #works return if $dlg->Show (-global) ne 'OK'; } sub changeEditPlayer { my ($id, $widget, $index, $value, $name) = @_; return 1 if ! defined $name; print "$name\n"; }
In reply to Re: How do I set the default item in a Tk::JComboBox
by zentara
in thread How do I set the default item in a Tk::JComboBox
by GrandFather
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |