Home Discussion Discuss: Changing the Label of a JButton Component in Java

  • hitsegalem December 10, 2011 at 2:42 PM

    this helped me a little bit. but i need to help me with implementing 9(3,3)buttons the firs and the last row will have initial label.and i want to move the labels to the closest free button.(its submission is December 19/2011)

  • Question for this codeAntonio January 30, 2012 at 12:16 AM

    Dear friend i have a similar problem to your example, but i have to put actionlistener in a different class outside of the the main class. to be more clear my problem is like that: import javax.swing.*; import java.awt.event.*; public class ChangeButtonLabel{ JButton button; public static void main(String[] args){ ChangeButtonLabel cl = new ChangeButtonLabel(); } public ChangeButtonLabel(){ JFrame frame = new JFrame("Change JButton Lebel"); button = new JButton("Click Me"); button.addActionListener(new MyAction()); frame.add(button); frame.setSize(400, 400); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class MyAction implements ActionListener{ public void actionPerformed(ActionEvent e){ String text = (String)e.getActionCommand(); if (text.equals("Click Me")){ button.setText("Roseindia.net"); } else{ button.setText("Click Me"); } } } I get an error that buttons is not cannot be resolved, any help wold be available.

  • javaankit September 12, 2012 at 7:00 PM

    when i click on any rectangle then co-ordinates changed....

  • super examplesathish March 25, 2013 at 11:54 PM

    java super example

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
Java-Tutorials

Changing the Label of a JButton Component in Java
Changing the Label of a JButton Component in Java... to change the label of a button in java swing. JButton is the component of javax.swing.*; package. The following program helps you to change the label of the button 

Java-Tutorials

Adding a Rollover and Pressed Icon to a JButton Component in Java
Adding a Rollover and Pressed Icon to a JButton Component in Java... about adding event i.e. the rollover and click icon to a JButton component of swing in java. Rollover means moving mouse pointer above the icon on the button.  

Java Tips and Examples

JButton
Java: JButton Description There are a few steps in using a button...; Icon image; JButton btn = new JButton(text); JButton btn = new JButton(text, image); JButton btn = new JButton(image 

Java-Tutorials

Java Swing : JButton Example
Java Swing : JButton Example In this section we will discuss how to create button by using JButton in swing framework. JButton : JButton Class extends... JButton labeling with some String .Some events are handled with the button 

Java Beginners

3D JButton in java?
3D JButton in java?  how we can create 3D button in java. thanks 

Java Beginners

Jbutton[] background & foregroundcolor change
Jbutton[] background & foregroundcolor change  how to change the color of the selected JButton in java swing. I am create JButton in an array JButton button[]=new JButton[100]; if i select button[5] then the Jbutton 

Java Beginners

jbutton - Java Beginners
jbutton  Hi, I have jlist and jbutton options.If i select... are displyed in the jlist using jbutton(refresh button). I want to know how to refresh... listModel; JList list ; public JListExample() { super(Select); JButton 

Swing AWT

Jbutton in JTable cells
Jbutton in JTable cells  I am a Java Beginner... I want a code in which I display data in Jtable from database and correspondingly a JButton for each cell and when i click on that button a new window should open 

Java Beginners

jbutton
jbutton  How to use enter function in jbutton?plzz help 

Java Beginners

Jbutton
Jbutton  How to get the enter key function in multiple jbutton 

Java-Tutorials

Java JButton Key Binding Example
Java JButton Key Binding Example In this section we will discuss about how... example which will demonstrate you about how to bind Enter key on JButton... components like JTextField for creating a textfield, JLabel for creating a label 

Java-Tutorials

Setting Multi-Line label on the Button
label on the button in Java Swing Applications. This program uses html class from javax.swing.text.html*; package and then breaks the text label... Setting Multi-Line label on the Button    

Programming Tutorials

Label in Flex4
Label in Flex4: In Flex4 Label is a lightweight and low level UI-component that is known as Spark Component in FLex4. Spark Label is used for rendering one or more lines of uniformly-formatted text. Label in Flex4 utilize the new 

General

java break to label tatement
Java Break to Label Statement In this article author discusses about Java Break to label Statement. 2005-06-30 The Java Specialists' Newsletter [Issue 110... via email or RSS. Welcome to the 110th edition of The Java(tm 

Java-Tutorials

JSlider Component of Java Swing
JSlider Component of Java Swing     ... component of Java Swing. A Slider is a Swing tool which you can use for selecting.... In this program, events on the JSlider component have also been shown. If you increase 

Java Beginners

how to move label in jframe in java?
how to move label in jframe in java?  please any one can give me code for moving a java label in Jframe 

Java Interview Questions

Java component
Java component  What is the preferred size of a component 

Java Beginners

Open TextFile on JButton Click - Java Beginners
Open TextFile on JButton Click  Hello Sir I Want to open TextFile on JButton Click. plz Help Me  Hi Friend, Do you want to simply open the text file or you want to open the file using JFileChooser,read that file 

JavaScript Questions

Dropdown and label issue
Dropdown and label issue  This is Venkat from Hyderabad,India.Working... suggestions.. Technologies I used are Java, J2ee, jsp,Servlets, Javascript... array with the size of label, and statred for loop, inside this I created one 

General

Sum of a Number using Swing
. JTextField, JButton is a component of GUI. Brief description of the Component used in this application : 1. JFrame is used to  creating  java...;JTextField(20); 3. JButton with a String as a label, and then drop 

Java Beginners

how to open a file with a jbutton? - Java Beginners
how to open a file with a jbutton?  Hello Is it possible that by clicking on a button it can open java html file or doc exists on the pc? I searched and I found that it is possible to open a web page so I tried to open 

Java-Tutorials

Making a component drag gable in java
Making a Component Draggable in Java       In this section, you will learn how to make a component... component to another. This program shows a text box and a label on the frame. When you 

Java Beginners

How to Open Text or Word File on JButton Click in Java - Java Beginners
How to Open Text or Word File on JButton Click in Java  How to Open Text or Word File on JButton Click in Java 

Swing AWT

How to set Marathi font to Label??
How to set Marathi font to Label??  Hello, I am doing one project in java-Swing Farm Management i want to set Marathi label in that so how i can? plzzzz help me its urgent 

Java Beginners

Dynamically update the Label & set Bounds constant between 2 Label(Thread)
in Dynamically update the label. when i m changing the the value in database , its...Dynamically update the Label & set Bounds constant between 2 Label(Thread...; private String findTagNo[ ]={ }; private JButton button1[]; private 

Java Beginners

Dynamically update the Label & set Bounds constant between 2 Label(Thread)
in Dynamically update the label. when i m changing the the value in database , its...Dynamically update the Label & set Bounds constant between 2 Label(Thread...; private String findTagNo[ ]={ }; private JButton button1[]; private 

Java Beginners

Dynamically update the Label & set Bounds constant between 2 Label(Thread)
in Dynamically update the label. when i m changing the the value in database , its...Dynamically update the Label & set Bounds constant between 2 Label(Thread...; private String findTagNo[ ]={ }; private JButton button1[]; private 

Java Beginners

How to add icons on a button or any component in java - Java Beginners
How to add icons on a button or any component in java  How to add icons on a button or any component in java?  Hi, import..."); JButton button = new JButton("Roseindia.net"); Icon imgicon = new ImageIcon 

JSF Tutorials & Examples

Tomahawk outputLabel tag
to set the label for any component in the page. Its for attribute is used to decide the component for which it is label. In the for attribute the id for that component is set. This is same as html label tag 

Java Interview Questions

Java component class
Java component class  Which method of the Component class is used to set the position and size of a component 

DMCA.com