Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8216525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:09:24+00:00 2026-06-07T12:09:24+00:00

I’m having a problem with in merging time and button together… I can’t get

  • 0

I’m having a problem with in merging time and button together…

I can’t get the button show in the JPanel.

This is my code:

import java.awt.Color;
import java.awt.Font;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public final class Date_Time extends JFrame{
    private static final long serialVersionUID = 1L;
    private JPanel show_date_time = new JPanel();
    private JLabel time = new JLabel("Time:");
    private JLabel show_time = new JLabel("Show Time");

    DateFormat dateFormat2 = new SimpleDateFormat("h:mm:ss a");
    java.util.Date date2;
    private JLabel label;
    private JPanel panel;

     public Date_Time(){
        this.setSize(300, 300);
        this.setResizable(false);
        getContentPane().add(Show_Time_date());
     }
     private JButton button1 = new JButton();
     private JFrame frame1 = new JFrame();
    public JPanel Show_Time_date(){
        frame1.add(show_date_time);
        show_date_time.setBackground(Color.ORANGE);
        frame1.add(button1);
        getShow_date_time().setLayout(null);
        Font f;
        f = new Font("SansSerif", Font.PLAIN, 15);
        getTime().setBounds(0,250,400,30);
        getTime().setFont(f);
        getShow_date_time().add(getTime());
        setShow_time(new JLabel(""));
        updateDateTime();
        getShow_time().setBounds(37,250,400,30);
        getShow_time().setFont(f);
        getShow_date_time().add(getShow_time());
        return getShow_date_time();

    }

    public static void main(String[] args) {
        Date_Time Main_win=new Date_Time();
        Main_win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Main_win.setVisible(true);
    }

    public void updateDateTime()
    {
    Thread th = new Thread(new Runnable()
        {
            @Override
        public void run()
            {
            while(true)
                {
                date2 = new java.util.Date();
                String dateTime = dateFormat2.format(date2);
                    getShow_time().setText(dateTime);
                    getShow_time().updateUI();

                }
            }
        });
    th.start();
    }

    /**
     * @return the show_time
     */
    public JLabel getShow_time() {

        return show_time;
    }

    /**
     * @param show_time the show_time to set
     */
    public void setShow_time(JLabel show_time) {
        this.show_time = show_time;
    }

    /**
     * @return the time
     */
    public JLabel getTime() {
        return time;
    }

    /**
     * @param time the time to set
     */
    public void setTime(JLabel time) {
        this.time = time;
    }

    /**
     * @return the show_date_time
     */
    public JPanel getShow_date_time() {
        return show_date_time;
    }

    /**
     * @param show_date_time the show_date_time to set
     */
    public void setShow_date_time(JPanel show_date_time) {
        this.show_date_time = show_date_time;
    }

    /**
     * @return the label1
     */


    /**
     * @param label1 the label1 to set
     */


    /**
     * @return the label
     */
    public JLabel getLabel() {

        return label;
    }

    /**
     * @param label the label to set
     */
    public void setLabel(JLabel label) {
        this.label = label;
    }

    /**
     * @return the panel
     */
    public JPanel getPanel() {
        return panel;
    }

    /**
     * @param panel the panel to set
     */
    public void setPanel(JPanel panel) {
        this.panel = panel;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T12:09:26+00:00Added an answer on June 7, 2026 at 12:09 pm

    Here have a look at this modified code :

    import java.awt.Color;
    import java.awt.FlowLayout;
    import java.awt.Font;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    
    public final class Date_Time extends JFrame{
    
        private static final long serialVersionUID = 1L;
        private JPanel show_date_time = new JPanel();
        private JLabel time = new JLabel("Time:");
        private JLabel show_time = new JLabel("Show Time");
    
        private DateFormat dateFormat2 = 
                    new SimpleDateFormat("h:mm:ss a");
        private JButton button1 = new JButton("USELESS");           
        private java.util.Date date2;
        private JLabel label;
        private JPanel panel;
    
        public Date_Time(){        
    
            //this.setResizable(false);
            getContentPane().add(show_Time_date());
        }    
    
        public JPanel show_Time_date(){
    
            getShow_date_time().setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
            /*
             * Always set this Opaque property of the 
             * said JComponent to true, before
             * you change the Background Colour
             * of the said component in question.
             * In some Look And Feels it's set to
             * false by default, so you won't
             * see any colour, in such situations.
             */
            getShow_date_time().setOpaque(true);
            getShow_date_time().setBackground(Color.ORANGE);        
    
            Font f;
            f = new Font("SansSerif", Font.PLAIN, 15);
    
            getTime().setFont(f);
            getShow_date_time().add(getTime());
            setShow_time(new JLabel(""));
    
            updateDateTime();
    
            getShow_time().setFont(f);
            getShow_date_time().add(getShow_time());
            getShow_date_time().add(button1);
    
            return getShow_date_time();
        }
    
        public static void main(String[] args) {
    
            /*
             * Calls like pack()/setSize()/setVisible()
             * must be done from inside the Event Dispatch Thread
             * or the EDT in short. And not from your
             * Main Thread. Please read Concurrency in Swing
             * in detail from this link : 
             * http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html
             */
            SwingUtilities.invokeLater(new Runnable()
            {
                public void run()
                {
                    Date_Time main_win=new Date_Time();
                    main_win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    main_win.setSize(250, 75);
                    main_win.setVisible(true);
                }
            });        
        }
    
        public void updateDateTime()
        {
            Thread th = new Thread(new Runnable()
            {
                @Override
                public void run()
                {
                    while(true)
                    {
                        date2 = new java.util.Date();
                        final String dateTime = dateFormat2.format(date2);
                        /*
                         * Any updates to the GUI, must also be done
                         * on the EDT - Event Dispatch Thread.
                         */
                        SwingUtilities.invokeLater(new Runnable()
                        {
                            public void run()
                            {
                                getShow_time().setText(dateTime);
                            }
                        });                    
                    }
                }
            });
            th.start();
        }
    
        /**
         * @return the show_time
         */
        public JLabel getShow_time() {
    
            return show_time;
        }
    
        /**
         * @param show_time the show_time to set
         */
        public void setShow_time(JLabel show_time) {
            this.show_time = show_time;
        }
    
        /**
         * @return the time
         */
        public JLabel getTime() {
            return time;
        }
    
        /**
         * @param time the time to set
         */
        public void setTime(JLabel time) {
            this.time = time;
        }
    
        /**
         * @return the show_date_time
         */
        public JPanel getShow_date_time() {
            return show_date_time;
        }
    
        /**
         * @param show_date_time the show_date_time to set
         */
        public void setShow_date_time(JPanel show_date_time) {
            this.show_date_time = show_date_time;
        }
    
        /**
         * @return the label1
         */
    
    
        /**
         * @param label1 the label1 to set
         */
    
    
        /**
         * @return the label
         */
        public JLabel getLabel() {
    
            return label;
        }
    
        /**
         * @param label the label to set
         */
        public void setLabel(JLabel label) {
            this.label = label;
        }
    
        /**
         * @return the panel
         */
        public JPanel getPanel() {
            return panel;
        }
    
        /**
         * @param panel the panel to set
         */
        public void setPanel(JPanel panel) {
            this.panel = panel;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.