participate


Swing - JButtons appearing in the Popup window?
This question is not answered.

<<   Back to Forum  |   Give us Feedback
This topic has 3 replies on 1 page.
dnguyen1022
Posts:18
Registered: 4/26/09
JButtons appearing in the Popup window?   
Nov 3, 2009 6:39 PM
 
 
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!
 
AndrewThompson64
Posts:3,837
Registered: 12/28/05
Re: JButtons appearing in the Popup window?   
Nov 3, 2009 7:38 PM (reply 1 of 3)  (In reply to original post )
 
 
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);
 
dnguyen1022
Posts:18
Registered: 4/26/09
Re: JButtons appearing in the Popup window?   
Nov 5, 2009 10:13 AM (reply 2 of 3)  (In reply to #1 )
 
 
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
 
DarrylBurke
Posts:15,598
Registered: 7/2/07
Re: JButtons appearing in the Popup window?   
Nov 5, 2009 10:31 AM (reply 3 of 3)  (In reply to #2 )
 
 
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

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics

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.

Powered by Jive Forums