Problem making buttons visible

Hi there, I have a poker game that all worked fine until I was told to restructure it in a MVC style. I never had this problem before I changed it but I'm having issues with making my buttons visible when it's the players turn. At first I setVisible to false which works fine, then I call my method to display them from my model and they display fine, so seemings as all is good to here I think it's the next bit that's causing my issue, I have actionListeners attached that when fired setsVisible on all the buttons to false again (which works) but the next time I call my method to make certain buttons visible they don't appear. I've tested that the method is being called with the correct parameter passed and it is. Now I must apologise because my knowledge of swing is very poor but I have searched and read alot and tried several approaches with no joy, I will definitly be studying up more on it in the future but time is against me at the mo. The only thing that seems to half work is if I use this.paint(g) the buttons display as I want them but my program crashes cos to be honest I don't know what g should be. Is this the right approach or is there a more simple way I can update my GUI to display my buttons?

Works for me but you could try to add a revalidate(); repaint(); on the buttons parent.
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
public class TestVisible {
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                final JButton button = new JButton("I do nothing");
                final JFrame frame = new JFrame("Test");
                frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                frame.getContentPane().add(button);
                frame.getContentPane().add(new JButton(new AbstractAction("Toggle") {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        button.setVisible(!button.isVisible());
//                        frame.getRootPane().revalidate();
//                        frame.getRootPane().repaint();
                }), BorderLayout.PAGE_START);
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
}

Similar Messages

  • Quick question - making button visible if two conditions are met

    I simply want a button to be visible is once condition is true and another condition is false. Shouldn't this line of code work?
    <mx:Button id="Btn"label="
    Submit"color="
    #FF0000"enabled="
    {islRequired}" visible=" 
    {!.isAdmin}  {isRequired}"
    click="submit()" 
    />
    isadmin = false
    isrequired = true
    the button should be visible
    Am I missing something?

    Maybe you miss OR (||) or AND (&&), but I never use at mxml
    visible="{!.isAdmin && isRequired}" 
    Works?
    Best Regards,
    Miguel

  • I continuously have a problem making calls where I have to activate then cancel the speaker phone button.  Normally happens when calling landline phones but sometimes mobile.  Any fixes?

    I continuously have problems making calls from my iphone 4S.  When I place a call and press send, you hear nothing until I turn on and off the speaker button and then you hear the ring tone or the person answering.  This happens normally on land line calls but does occur when calling mobile phones somethimes.  Is this a common problem or is there a fix for it?  Thanks

    I am having the same problem. Usually happens after I make consecutive phone calls.

  • Making a button visible upon closing a document

    Kind of a weird question, but is there a way to make a button visible upon closing a document? Here's my situation. I want users to click a link which will open a PDF. I then want the users to take a quiz based off of the information in the PDF. Is there a way to have the users click the link to open the PDF, then a button to start a quiz becomes visible when the users close the PDF? I have a feeling it's probably not possible, but I figured I'd check. Thanks.

    I was actually able to find a bit of a workaround. I created an advanced action to open the PDF and show the button (it was hidden to begin with) once I click the hyperlink. It's not exactly what I wanted to do, but I think it'll suffice until I figure out a way to show the button upon closing the PDF. I'll look into the java scripting, even though I'm not really a coder. Thanks!

  • Problem with buttons in my screens

    hi
    i have two buttons in my screen say button1 and button2
    by default when i display this screen as per my requirement only button1 should be visible and button2 should be invisible
    button2 should only be visible when i click on my first button i.e. button1.
    where and how to code this
    vamsi

    Hello Sir,
    This is Ravi and Saras this side.
    Remember?
    TCS.....SAP Training.....Lemon Tree...
    Ok.
    As far as ur question is concerned.....
    1. At selection-screen output
         loop at screen.....then make the 2nd button invisible by modifying the screen.
    2. At selection-screen
         Between an if endif condition check whether the 1st button has been clicked.
         If yes then again loop at screen and make the 2nd button visible.
    That will solve ur problem.
    Regards,
    Ravi and Saras

  • Button visible

    Hello,
    How can i make a button visible if a shared variable is true and not visible if that same varable is false...?? is this possible??

    Romain_H wrote:
    I would like to do the same but the problem is i have to run the vi each time.
    If you want to switch visibility with a FP control while the VI is in edit mode, you can make an xcontrol consisting of a button and a switch for its visibility.
    Typically, you should design your VI such that it always runs during use. It can be in a wait state when it's not supposed to do anything.
    LabVIEW Champion . Do more with less code and in less time .

  • Strange solution to problem of buttons dissappearing in Encore 2.0

    I've pulled my hair over a problem with buttons dissappearing at preview. They are nice looking in the menu window, I can route them and so on, but when previewing they simply dissappear, or sometimes become partly visible, or sometimes become displaced.
    Now, I found that one solution to this is to place a new button in the menu, possibly onto the same place as another button already there. Then a immediately remove the newly placed button. After that problem seems solved, at least until I move or handle my buttons again. Might someone explain how this is possible? What in Encores internal workings can explain this? Deleting the cache folder didn't solve it. mind you.
    Regards,
    Nikolaj

    I have not analyzed the buttons in PS. How do I do that? I'll have to export the buttons as PS-files first, right?
    You are correct. Just use Edit in Photoshop, and the program will launch, and then Open your Menu.
    Once in PS, you will want to make sure that the Layers Palette is Open and visible. You will see several Layer Sets. Most will be your Buttons. When you click on the little triangle, at the left-side of the Button Layer Set, it will "twirl-down" all of the included Layers. Note that the Button Layer Sets, and each enclosed Layer will have some odd names. The first several characters in those names are VERY important. These MUST be correct, for the PSD file to function as a Menu.
    Also, don't worry about any mis-steps. That comes from not knowing the program yet.
    Take note that just because I have not encountered a problem with EncoreDVD 2.0, does not mean that it does not exist. I have done many, many Projects, and burned many successful discs, but then I do things the same exact way for each Project. Pretty boring, I will admit, but if it works, then I have few reasons to change anything.
    Now, I do get to exercise my artistic side with the Menus and the navigation, but the rest of it is rather "by the numbers."
    One note on Edit in Photoshop: this operation will create a TMP file of your Menu. It is THAT file, that is Opened. Look at the name. It'll be rather cryptic. When you make a change, in PS, and hit Save (Ctrl+S), those changes are transferred back to Encore. Do not do a Save_As, unless you have a good reason to do so, or Encore will still have the old Menu, and it will not update.
    Also, there are instances, where a simple Save does NOT update Encore. Through trial and error, I have found that if one does three (3) Saves, this gets past whatever that glitch is. Normally, I just use Ctrl+S, at least 3x, during the editing process, whether I have any indication that the Save is not working, as it should. It has now become habit for ALL Menus in my workflow, though the problem seems to only happen about 1:8 Menus.
    Good luck,
    Hunt
    PS - If you have any questions on your Menu and your Button Layer Sets, do not hesitate to do a screen-cap, and attach that. Hint: use the little "camera" icon in the lower-middle of the editing screens Toolbar. We'll all take a good look at it. I'd Save that as a JPEG @ ~ a compression of 9 on the PS scale, so we can read the "fine print."

  • I want make my button visible or invisible on click of button

    Hi All
    I want make my button visible or invisible on click of button.
    Regards
    Kirankumar M

    HI Kiran,
    Your Question:
    onclick button should be visible and on second click it should become invisible.
    Answer:
    In your View
    1.Add Two button using Apply Template--actionButton
      So two buttons will get added to the view
    2.Create an attribute in View Context say buttonset of type com.sap.ide.webdynpro.uielementdefinitions.Visibility
    Bind the visible property of second button to buttonset attribute
    This attribute is  to set visibility
    Also create a booloean attribute bool in the View context
    3.In DoInit method
    wdContext.currentContextElement().setBool(true);
    So that both buttons are visible in View initially
    4.In First button event handler onActionButton()
    call second button eventhandler onActionButton_0()
    public void onActionButton(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
        //@@begin onActionButton(ServerEvent)
           onActionButton_0(wdEvent);
        //@@end
    Here onActionButton_0() is like one method which is actually making second button visible or invisible based on boolean value bool=true /bool=false
    5. Write the following code in onActionButton_0() to perform the actual action
        if(wdContext.currentContextElement().getBool()==true){
                wdContext.currentContextElement().setButtonset(WDVisibility.NONE);
                wdContext.currentContextElement().setBool(false);
    else{
           wdContext.currentContextElement().setButtonset(WDVisibility.VISIBLE);
                      wdContext.currentContextElement().setBool(true);
    6.Now build and deploy ans run your application.
    It works..
    Nice Question..
    I was excited trying this...
    Hope it helps You
    Regards,
    Archana
    Edited by: Archana CTS on Mar 19, 2009 2:08 PM

  • Problem making/receiving/disconnecting calls and p...

    I was looking for a new phone to replace my old Samsung Star, but I was unable to justify this expense. So, I saw Nokia Lumia 710 with it's GPS software and hardware as part of the package. Windows phone looks so beautiful that I just bought it last march, 23th.
    Now, verifying this forum I realize that my problem, some how, exists since January in Europe. As many people here I have problems to end a call, but in my case the call never completes and when I try to disconnect Lumia just does nothing beyond show "disconnecting" forever. The only way to recover control is turning Lumia off.
    Its true that my carrier has a very weak signal where I live (at my apartment), but my old Samsung at least make and receive calls. Some times I must move near to the window to have a better reception, but works. With Lumia, different from what I was expecting (a premium Nokia quality signal  - the best possible reception), some times just do not work! Some times people calls me and the phone do not ring. Some times I receive that screen offering me the opportunity to send a message like "I'm at a meeting" or something like that, but I do not have the opportunity to receive that call. This is very frequent since I bought this Nokia. Some times, when I make a call, Lumia pretend to call, pretend that the other person is connected, but, in fact, there is no calling sound. The phone remains mute all the time, there are no call. When I give up, I press "disconnect" and Lumia shows "disconnecting" but nothing happens. To recover phone control I must turn it off to try again. Once I was so angry that I press many buttons and Lumia freezes up completely and was needed to remove battery to turn off.
    About GPS, that was my main excuse to expend a lot of money on a new phone: Nokia Lumia GPS is disappointing. Lumia GPS looks like loose satellite signals very frequently. I decided to make a comparison between my Lumia and my wife's iPad. Working totally offline, side by side at my wife's lap, while iPad was able to show immediately every turn I make, Lumia takes long time to realize that. In fact, most of time, Lumia just realize that I turn when I was reaching next corner. I'm using Nokia drive 2 and, in this test, since I don’t have a GPS software at iPad, I just leave Lumia and iPad with the map showing our position. I do not set a destination.
    Finally, my last disappointment is about windows Phone and the “one account policy”. Really? They think people will be happy to give up from their messenger accounts or Xbox accounts to use Windows Phone? When I turn on my Lumia for the first time it asks me to enter or create a Microsoft account. I think about and I realize that I don’t want to add payment information to my very old Hotmail/messenger account, so, I create a new one. My mistake because soon I discover that Windows Phone do not let me choose a different account for Messenger or Xbox.
    I call Nokia in Brazil to find a solution for my two main problems: making/receiving calls and the GPS performance. The only solution they can think about was reset my phone. I do that a few hours ago. This time I choose to enter my Messenger account to be able to chat with my friends, but, of course, I loose my Xbox id created with the other account.
    “One account policy” is so “not smart” that is very hard to understand why they do that. The need to reset the device to choose another account is unbelievable. Mean while, with iPhone/iPad, to change accounts is so easy…
    I will test my phone for the next few days to verify if reset solve all my problems, but right now I’m very disappointed.
    (I hope you can understand my poor english).

    Reset Lumia 710 do not solved my problem. I was forced to send the device to technical support. Even if they was unable to reproduce the problems I faced at home, they did a flash reset (or something) and now my phone always ring when people call and I can end calls without a problem. For now those problems disappeared.

  • Having problem making purchases in game? Credit Card set up and previously made many purchases.

    Having problem making purchases in game? Credit Card set up and previously made many purchases.

    What happens when you try to buy them, does the 'buy' button not work, do you get any error messages ... ?
    If you are getting a message to contact iTunes Support then you can do so via this link and ask them for help (we are fellow users here on these forums, we won't know why the message is appearing) : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption
    If it's a different problem ... ?

  • I no longer have access to the back up email address I used when I set up my apple ID. I have since forgotten the answers to my security questions and am having a problem making changes to my account. What can I do?

    I no longer have access to the back up email address I used when I set up my apple ID. I have since forgotten the answers to my security questions and am having a problem making changes to my account. What can I do?

    You need to ask Apple to reset your security questions. To do this, click here and pick a method; if that page doesn't list one for your country or you're unable to call, fill out and submit this form.
    They wouldn't be security questions if they could be bypassed without Apple verifying your identity.
    (114957)

  • Making button and a html site in visual studio community version

    Hi,
    I like to Making button and a html site  in visual studio community version but i dont know how to put the right code in my c# form to perform a action to my new html site i made with visual studio.
    So ik have a button and i added a html site with the "add" options to my form.I want the button to open onclick that site so i can make a html about some info of the button image (tool to use with metal)
    Any one? Sorry i am very new at this and also from the netherlands but i want to  coding in c# great to to learn..
    Many thanks!
    Arend

    Hi Arend,
    Thank you for posting in MSDN forum.
    Since this forum is to discuss: Visual Studio WPF/SL Designer, Visual Studio Guidance
    Automation Toolkit, Developer Documentation and Help System, and Visual Studio Editor. Based on your issue, I think that the issue is more related to the programming. So I’m afraid that it is not the correct forum for this issue.
    To help you find the correct forum for this issue, could you please tell
    me which kind of app you want to create? Is it winform app or others?
    If you want to code for a winform app using c# language, I suggest you
    can consult your question on specific
    WinForm forum so that they can share you something for you to start.
    Thanks for your understanding.
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Problem placing buttons on top of a background image

    My knowledge of Java isn't the greatest and I am currently having problems placing buttons on top of a background image within a JApplet (this is also my first encounter with Applets).
    I'm using a Card Layout in order to display a series of different screens upon request.
    The first card is used as a Splash Screen which is displayed for 5 seconds before changing to the Main Menu card.
    When the Main Menu card is called the background image is not shown but the button is.
    While the Applet is running no errors are shown in the console.
    Full source code can be seen below;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.net.*;
    // First extend JApplet
    public class WOT extends JApplet {
         //--------------- Variables are declared here -----------------
         private CardLayout contentCardLayout = new CardLayout();  // declare CardLayout
         private Container contentContain;     // declare content Container
         private JPanel contentCard, splashScreen, mainMenu, menuImage; // declare content Panels
         private JLabel splash, menu, map; // declare image labels
         private ImageIcon mapBtn; // declare ImageIcons
         private JButton mapOption; // declare option Buttons
         private Timer timer; // declare Timer
         private ActionListener actionListener, mapOptionListener; // declare ActionListener
    //--------------- Initialise Applet -----------------
      public void init() {
         //--------------- Set-up Card Layout -----------------
         contentCard = new JPanel(contentCardLayout); // assign card panels to CardLayout
         //--------------- Splash Screen -----------------
         splashScreen = new JPanel();
         splash = new JLabel(new ImageIcon(getClass().getResource("img/bg.gif")));
         splashScreen.add(splash);
         splashScreen.setSize(600,800);
         splashScreen.setLocation(0,0);
    //--------------- "View Map" Option Button -----------------
         mapBtn = new ImageIcon(getClass().getResource("img/map.gif"));
         mapOption = new JButton(mapBtn);
         mapOption.setBorder(null);
         mapOption.setContentAreaFilled(false);
         mapOption.setSize(150,66);
         mapOption.setLocation(150,450);
         mapOption.setOpaque(false);
         mapOption.setVisible(true);
    //--------------- Main Menu Screen -----------------
         //menuImage = new JPanel(null);
         //menuImage.add(mainMenu);
         //menuImage.setLocation(0,0);
         mainMenu = new JPanel(null);
         menu = new JLabel(new ImageIcon(getClass().getResource("img/menu.gif")));
         menu.setLocation(0,0);
         mainMenu.add(menu);
         //mainMenu.setBackground(Color.WHITE);
         mainMenu.setLocation(0,0);
         mainMenu.setOpaque(false);
         //mainMenu.setSize(150,66);
         mainMenu.add(mapOption);
         //--------------- Map Image Screen -----------------
         map = new JLabel(new ImageIcon(getClass().getResource("img/map.gif")));
         //--------------- Add Cards to CardLayout Panel -----------------
        contentCard.add(splashScreen, "Splash Screen");
         contentCard.add(mainMenu, "Main Menu");
         contentCard.add(map, "Map Image");
    //--------------- Set-up container -----------------
          contentContain = getContentPane(); // set container as content pane
          contentContain.setBackground(Color.WHITE); // set container background colour
           contentContain.setLocation(0,0);
           contentContain.setSize(600,800);
          contentContain.setLayout(new FlowLayout()); // set container layout
           contentContain.add(contentCard);  // cards added
           //--------------- Timer Action Listener -----------------
           actionListener = new ActionListener()
                    public void actionPerformed(ActionEvent actionEvent)
                             //--------------- Show Main Menu Card -----------------
                             contentCardLayout.show(contentCard, "Main Menu");
         //--------------- Map Option Button Action Listener -----------------
           mapOptionListener = new ActionListener()
                    public void actionPerformed(ActionEvent actionEvent)
                             //--------------- Show Main Menu Card -----------------
                             contentCardLayout.show(contentCard, "Map Image");
         //--------------- Timer -----------------               
         timer = new Timer(5000, actionListener);
         timer.start();
         timer.setRepeats(false);
    }Any help would be much appreciated!
    Edited by: bex1984 on May 18, 2008 6:31 AM

    1) When posting here, please use fewer comments. The comments that you have don't help folks who know Java read and understand your program and in fact hinder this ability, which makes it less likely that someone will in fact read your code and help you -- something you definitely don't want to have happen! Instead, strive to make your variable and method names as logical and self-commenting as possible, and use comments judiciously and a bit more sparingly.
    2) Try to use more methods and even classes to "divide and conquer".
    3) To create a panel with a background image that can hold buttons and such, you should create an object that overrides JPanel and has a paintComponent override method within it that draws your image using the graphics object's drawImage(...) method
    For instance:
    an image jpanel:
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.net.URISyntaxException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    public class BackgroundImage
        // **** this will have to be changed for your program:
        private static final String IMAGE_PATH = "../../m02/a/images/Forest.jpg";
        private BufferedImage myImage = null;
        private JPanel imagePanel = new JPanel()
            @Override
            protected void paintComponent(Graphics g)
            {   // *** here is where I draw my image
                super.paintComponent(g);  // **** don't forget this!
                if (myImage != null)
                    g.drawImage(myImage, 0, 0, this);
        public BackgroundImage()
            imagePanel.setPreferredSize(new Dimension(600, 450));
            imagePanel.add(new JButton("Foobars Rule!"));
            try
                myImage = createImage(IMAGE_PATH);
            catch (IOException e)
                e.printStackTrace();
            catch (URISyntaxException e)
                e.printStackTrace();
        private BufferedImage createImage(String path) throws IOException,
                URISyntaxException
            URL imageURL = getClass().getResource(path);
            if (imageURL != null)
                return ImageIO.read(new File(imageURL.toURI()));
            else
                return null;
        public JPanel getImagePanel()
            return imagePanel;
    }and an applet that uses it:
    import java.lang.reflect.InvocationTargetException;
    import javax.swing.JApplet;
    import javax.swing.SwingUtilities;
    public class BackgrndImageApplet extends JApplet
        @Override
        public void init()
            try
                SwingUtilities.invokeAndWait(new Runnable()
                    @Override
                    public void run()
                        getContentPane().add(new BackgroundImage().getImagePanel());
            catch (InterruptedException e)
                e.printStackTrace();
            catch (InvocationTargetException e)
                e.printStackTrace();
    }

  • Problem in button

    hi,
    at present i am working in oracle forms
    in that while i am running the form, in the MDI window max,min,close button will appear,
    my problem is i don't want that button ,that buttons should not appear while running
    what to do for that

    hi
    pls..do not post the same quetion multiple times
    follow the link
    problem in button
    thanks
    Kris

  • Anyone else having problems making a hyperlink to a file in CS4?

    Anyone else having problems making a hyperlink to a file? 
    I have a document in CS4 that I'm exporting to pdf. When I create a hyperlink in CS4 to a file, I am getting the message when I click the link in the pdf ' Cannot find the file:C%5Document' etc. 
    When creating the link, File is selected, Shared Destination is unchecked & checking the link using 'Go to Destination' shows the link works. 
    In Acrobat 9 Pro, I've checked the properties of the link - when exported from CS4, the Link Properties - Actions are 'Open a web link' 'file:C:\Documents%20'etc whereas if the link is created in Acrobat the link properties are ' 'Open a file' 'file:C\Documents and Settings' etc, and it works. 
    Is this a bug or am I missing something?

    I'm only getting that to work with the catalogue & sample in the same folder. In any case from a useability standpoint using URL brings up the Security Warning & putting the catalogue pdf in the same folder as 100 sample pdfs makes it more difficult to locate.
    I'm at a loss to understand why the functionality of creating a link in InDesign cannot be the same as Acrobat; where you can select 'Open a file', browse to that file and the relative links are maintained when you burn to a disc. InDesign looks as if it will do the same but when you select File as the link & browse to the destination file but InDesign treats it as a URL & brings up the the web link cursor in the finished pdf. That still looks like a bug to me.

Maybe you are looking for

  • BW upgrade - development box

    Hi, we will be upgrading development followed by quality, In norm cases, do we delete the data loads in BW development to ensure the size is smaller or is that ok to let the data remain in the development system during the bw upgrade? apppreciate if

  • Can't connect to Eduroam on my WP 8 Nokia Lumia 930

    Hi! So, I just got the new Lumia 930, which I am very happy with, however I can not seem to get it to connect to Eduroam at the university I work at. When I go to the page where I am suppose to 'join' or 'download' whatever I need, 'securew2', (using

  • Can I change where the comments go in Pages?

    The comments that I can add by clicking the yellow sticky note looking button are great, but sort of annoying. I want to put them on the right rather than the left since there's more space when I expand the page. Is there anyway to do this?

  • HELP!! cruising with no service need to use my phone

    I'm currently on a cruise round the med I need to use my phone but have no service to do so please can anyone help! I only have 24hrs of wifi.

  • Fscommand exec problem

    Hello everybody, I know similar questions have been many times asked on this forum, and I've read them and tried the diffrent solutions proposed, without attaining my goal. My goal is to launch a software some_software.exe with an executable projecto