jQuery in Action, 3rd edition
The moose likes Swing / AWT / SWT and the fly likes Button Action using netbeans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Button Action using netbeans" Watch "Button Action using netbeans" New topic

Button Action using netbeans

v kishore

Joined: Oct 23, 2010
Posts: 11
Hi Forum,
I am new to swing , netbeans . using netbeans ui components i set the button and text filed on the panel , set the button text to click ,

my intention is when i click on that button using mouse it have to show message " hai" in the text field . a simple example for my understand .

here i don't understand how can perform this action .

on the button while using the event action perform in the code it show the
following function.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:

to show the hai message in the textfield i add jTextField1.setText("hai"); as shown,

but while check this using preview design there no action takes places .

so please help me how can i perform this action using netbeans ui and action perform in code

below i am pasting the code generated by netbeans through ui.

thanks in advance

public class NewJPanel extends javax.swing.JPanel {

/** Creates new form NewJPanel */
public NewJPanel() {

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();


jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
.addGap(34, 34, 34)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(248, Short.MAX_VALUE))
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(16, 16, 16)
.addContainerGap(241, Short.MAX_VALUE))
}// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JTextField jTextField1;
// End of variables declaration


Darryl Burke

Joined: May 03, 2008
Posts: 5093

Dump the NetBeans visual designer. It may look like a beginners' tool, but it isn't.


luck, db
There are no new questions, but there may be new answers.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3151

Agree with Darryl. And you dont get to learn much once you use a designer tool.

Mohamed Sanaulla | My Blog
v kishore

Joined: Oct 23, 2010
Posts: 11
Hi thanks for your replies and suggestions,
i designed it , here the problem appears only when i extend from jpanel if i use jframe i get the desired output .

i am able to run the code but see the out put only when i my class extend from jframe instead of jpanel .can you suggest why it happen .


I agree. Here's the link: http://aspose.com/file-tools
subject: Button Action using netbeans
It's not a secret anymore!