Hello
i'm trying to display date in textfield
this is my code:

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

    java.util.Date date=new java.util.Date();
    this.DateObject.setText(date.toString());

olny the problem is the date will only show If i press a button
I want it to display automatically when I run the programme without the need to press any buttons
i'm using netBeans GUI Bilder
thank you

Recommended Answers

All 3 Replies

I want it to display automatically when I run the programme without the need to press any buttons

Set the text field's content in your constructor.

try this code:

Date date = new Date(); //declare this above;
txtFieldDate.setText(date.toString()); //set this inside you class.

Hi tyranx, welcome to DaniWeb.
Did you notice the date of this thread? It was marked as "solved" five months ago, so your answer is a little late!
Your contributions are very welcome - have a look at some of the more recent topics tha thave not yet been marked so"solved".
JC

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.