#!/usr/bin/perl use warnings; 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;