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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:04:06+00:00 2026-05-23T02:04:06+00:00

I have class Probability . I want use custom renderer for it (already done)

  • 0

I have class Probability. I want use custom renderer for it (already done) and double like editor. But I can’t even find double editor (only Number), so I really have no idea how I should implement it. The question is: how I should implement it?

*difference from double editor: it should permit only numbers in range 0..100

  • 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-23T02:04:07+00:00Added an answer on May 23, 2026 at 2:04 am

    What about a JFormattedTextField with an AbstractFormatter doing the conversion, and a DocumentFilter to reject anything which is not a valid percentage value?

    Here is an example DocumentFilter (not tested, from reading the documentation):

    class PercentageFilter extends DocumentFilter {
        insertString(FilterBypass bp, int offset, String adding, AttributeSet attrs) {
            Document doc = bp.getDocument();
            String text = doc.getText(0, offset) + adding + doc.getText(offset, doc.getLength()-offset);
            try {
                double d = Double.parseDouble(text);
                if(d < 0 || 100 < d) {
                    // to big or too small number
                    return;
                }
            }
            catch(NumberFormatException ex) {
                // invalid number, do nothing.
                return;
            }
            // if we come to this point, the entered number
            // is a valid value => really insert it into the document.
            bp.insertString(offset, adding, attrs);
        }
    }
    

    You would want to override remove() and replace similarly.

    (I suppose there could be a more efficient implementation, but this will be fast enough for most user’s typing speed, I suppose.)

    This filter would be returned from your AbstractFormatter implementation’s getDocumentFilter method.

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

Sidebar

Related Questions

I have class (MyCustomWebView) that extend webview can i do something like this ?
I have class method that returns a list of employees that I can iterate
I have: class Car {..} class Other{ List<T> GetAll(){..} } I want to do:
I have class A: public B { ...} vector<A*> v; I want to do
I have class MyContainer < ActiveRecord::Base :has_many MyObjects, :dependent => :destroy end I want
I have class like public class ProgressBars { public ProgressBars() { } private Int32
I need a class that can represent probabilities. It can be represented like a
I have a class like the following: class MyClass(object): def __init__(self, input1, input2): self.attribute1
I have class like this: public class object { [Key] int number; String mystring;
I have class and I want to reproduce the functionality associated with ToString(0.0000) as

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.