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 3665762
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:47:59+00:00 2026-05-19T01:47:59+00:00

I have a JTextField represents a day in a week, such as Friday, when

  • 0

I have a JTextField represents a day in a week, such as “Friday”, when I click on it, I want to have a choice such as “1st of month, 3rd of month or last of month”, so I came up with two options :

<1> Hold down a number or letter, let’s say “2” or “L”, then click on “Friday” means 2nd (or last) Friday of the month, in this case, how to get the number while mouse clicks on the JTextField ?

<2> Right mouse click on the “Friday” JTextField, drop down a menu, with either buttons or checkboxes that let me choose, then close the menu and get the value.

My code look like this so far :

  private final JTextField[] dayHeadings=new JTextField[]{new JTextField("Su"),
                                                          new JTextField("Mo"),
                                                          new JTextField("Tu"),
                                                          new JTextField("We"),
                                                          new JTextField("Th"),
                                                          new JTextField("Fr"),
                                                          new JTextField("Sa")};
......

    for (int ii=0; ii < dayHeadings.length; ii++)
    {
      dayHeadings[ii].setEditable(false);
      dayHeadings[ii].setFocusable(false);
      dayHeadings[ii].addMouseListener(new MouseAdapter() { public void mouseClicked(final MouseEvent evt) { onHeadingClicked(evt); } });
      add(dayHeadings[ii],new AbsoluteConstraints(x,38,X_Cell_Size+1,Y_Cell_Size+1));
    }
......
  void onHeadingClicked(final java.awt.event.MouseEvent evt)
  {
    final javax.swing.JTextField fld=(javax.swing.JTextField) evt.getSource();

    ...
  }

How to do either of the above, are they doable in Java ?

  • 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-05-19T01:48:00+00:00Added an answer on May 19, 2026 at 1:48 am

    Option 1:

    There is no way to do this in one step. You would need to add a KeyListner to track whenever a key is pressed and then save the character value. Then you would need to add a MouseListener to listener for mousePressed events. When the mousePressed event fires you would need to to check which character is saved and then do your processing. Therefore your listener would to implement both the KeyListener and MouseListener interfaces.

    Option 2:

    You need to add a mouse listener and listen for a right mouse click, then display a popup menu.

    I think option 2 is more intuitive and more easily done. Its always easier to work with one hand then be forced to use two hands.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a disabled JTextField and due to readability problems i want to make
I have a JFrame that contains a display JPanel with JTextField and a control
I have a JPanel full of JTextFields... for (int i=0; i<maxPoints; i++) { JTextField
How do I manipulate textfield variables within an iPhone app? I want to have
I have a Django model that looks like this. class Solution(models.Model): ''' Represents a
I want to model an article with revisions in Django: I have following in
I have a JTextField with a Suggestion-Popup. A DocumentListener listen to all InsertUpdate-Events and
I want to be able to have a JPanel in a cell with a
I want to have generalised email templates. Currently I have multiple email templates with
This one's a tough one - I have a JFrame that generates JTextFields. When

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.