How to Toggle Text in Java

When writing a program in Java, you may want to create a block of text that can disappear or reappear based on a user's action, such as the pressing of a button in the program. You can create this toggle option with a built-in function in Java that turns any block of text into a toggle-able block that you can then attach to a button object.

Instructions

    • 1

      Open your Java program project in your editor of choice.

    • 2

      Create a small block of text and save it into a variable by typing the following:

      string yourString = "This is your text that will be toggled";

    • 3

      Type the following on a new line:

      new object.button(yourbutton,toggleDisplay(yourString,visible));

      This creates a new button object that is associated with your string. This button has the "toggleDisplay" property set on it, which will cause it to make the text alternate between being visible and invisible when clicked.

Related Searches:

Comments

Related Ads

Featured