Dynamic Buttons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    Dynamic Buttons

    Why would you ever want to create a button dynamically?
    A button seems like a pretty concrete thing to have in an application; it requires you to implement code that handles its events....and usually we want a button to perform a specific task (really I can't think of a case where this doesn't happen).

    So why would anyone want to create a button dynamically?

    -Frinny
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by Frinavale
    Why would you ever want to create a button dynamically?
    A button seems like a pretty concrete thing to have in an application; it requires you to implement code that handles its events....and usually we want a button to perform a specific task (really I can't think of a case where this doesn't happen).

    So why would anyone want to create a button dynamically?

    -Frinny
    I always keep a method like makeButton ready though, there's a bit you have to do to initialize a button in Java and often I fing that I don't want to write the same thing over and over again.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by r035198x
      I always keep a method like makeButton ready though, there's a bit you have to do to initialize a button in Java and often I fing that I don't want to write the same thing over and over again.

      I can see where it could come in handy for a Java application...b ut you still hard code the method that handles it's "click" event.

      It just seems that lately I've been encountering questions in .NET where a user creates a button on the fly and then they get stuck and ask us how to dynamically supply code for said button.

      I wonder why the don't just create a button and make it visible or invisible depending on whatever their logic dictates.

      It's not like Java where you have to declare the button, and then set up where it should be in some box that functions as your window (can't remember what it entails but I remember it being painful to do)...you just drag the button onto a form and go from there.

      Isn't there some sort of Java editing software out there that is something like Visual Studio that lets you do this too?

      -Frinny

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by Frinavale
        Why would you ever want to create a button dynamically?
        A button seems like a pretty concrete thing to have in an application; it requires you to implement code that handles its events....and usually we want a button to perform a specific task (really I can't think of a case where this doesn't happen).

        So why would anyone want to create a button dynamically?

        -Frinny
        If you have a undetermined dataset with an unknown number of elements, couldn't it be useful to be able to dynamically build buttons?

        The only real reason why someone would be caught up on building handlers is if they did not use an object oriented approach to building the buttons. If I were to do something like this, I would build (or extend) a button class to include the related data elements, handler specifics, position, and style information.

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Originally posted by Motoma
          If you have a undetermined dataset with an unknown number of elements, couldn't it be useful to be able to dynamically build buttons?

          The only real reason why someone would be caught up on building handlers is if they did not use an object oriented approach to building the buttons. If I were to do something like this, I would build (or extend) a button class to include the related data elements, handler specifics, position, and style information.
          That's why the DataGrid / GridView control was created :)

          Comment

          • Motoma
            Recognized Expert Specialist
            • Jan 2007
            • 3236

            #6
            Originally posted by Frinavale
            That's why the DataGrid / GridView control was created :)
            Yes, however the DataGrid/DataView objects are very restrictive in the way they allow one to present data.

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              Originally posted by Motoma
              Yes, however the DataGrid/DataView objects are very restrictive in the way they allow one to present data.
              And edit/delete/update the data in the dataset.....

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                I guess this is a good indication that I should get cracking on that DataGrid/GridView article.

                Hehe

                Comment

                • Motoma
                  Recognized Expert Specialist
                  • Jan 2007
                  • 3236

                  #9
                  Originally posted by Frinavale
                  I guess this is a good indication that I should get cracking on that DataGrid/GridView article.

                  Hehe
                  Let me know if you want any help with content or proofreading.

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by Frinavale

                    Isn't there some sort of Java editing software out there that is something like Visual Studio that lets you do this too?

                    -Frinny
                    Unfortunately there's lots of them these days. More often than not though, I'd have one method called for all my button clicks (or for a set of similar actions) and then it would be easy to add more functionality if my buttons were made "dynamicall y" especially in cases where the interface itself is dynamic and I'm showing and hiding buttons.

                    It is also possible to over-do-it though ...

                    Comment

                    Working...