This topic has
3
replies
on
1
page.
So currently my GUI code creates a JPopupMenu with JButtons appearing in it. However when my popup appears, the button appears, but it doesn't appear in the same window.
Here are the main parts of my code that does the displaying of the menu and buttons.
public class NumMenu extends JFrame {
private JButton numbers[];
private int numValues[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
public NumMenu(){
super( "Pick your number" );
final JPopupMenu numPopup = new JPopupMenu();
ItemHandler handler = new ItemHandler();
String nums[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9"};
numbers = new JButton[9];
for(int i = 0; i != numbers.length; i++){
numbers[i] = new JButton(nums[i]);
numPopup.add(numbers[i]);
numbers[i].addActionListener(handler);
this.setSize(300, 300);
numPopup.setVisible(true);
How do I modify the buttons so that the buttons are actually in the popup? I want to be able to drag the popup window around and the buttons should also follow. Thanks for your help!
Please use the code tags when posting code, code snippets, XML/HTML or input/output. To do that, select the code and click the CODE button.
E.G.
public class NumMenu extends JFrame {
private JButton numbers[];
private int numValues[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
public NumMenu(){
super ( "Pick your number" );
final JPopupMenu numPopup = new JPopupMenu();
ItemHandler handler = new ItemHandler();
String nums[] = { "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" } ;
numbers = new JButton[9];
for (int i = 0; i != numbers.length; i++){
numbers[i] = new JButton(nums[i]);
numPopup.add(numbers[i]);
numbers[i].addActionListener(handler);
this.setSize(300, 300);
numPopup.setVisible(true );
I still need help with this guys..Thank you Andrew for pasting my code correctly!
Edited by: dnguyen1022 on Nov 5, 2009 10:13 AM
To get better help sooner, post a
SSCCE that clearly demonstrates your problem.
db
This topic has
3
replies
on
1
page.
Back to Forum
Read the Developer Forums Code of Conduct
Email this Topic
Edit this Topic
Site Upgrade
Forums 7.1.8 was deployed Oct 26th. The release consists of minor fixes & a few enhancements.
About Sun forums
Sun Forums is a large collection of user generated
discussions. It is here to help you ask questions, find answers, and
participate in discussions.
Check out our guide on Getting
started with Sun Forums for a full walkthrough of how to best
leverage the benefits of this community.