Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Advice on creating my own Swing component  RSS feed

 
Martin Mutilva
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to create a new Swing component I describe in the following lines:

Component description:

I want to extend JTextField or JFormattedTextField, so my new component can be easily bound to a BigDecimal variable.

The component will have customizable scale and lengthproperties.

Behavior:

When the component is drawn, it shows only the decimal point and space for scale digits to its right.

When the component receives focus the caret should be positioned left to the decimal point. As the user types numbers (any other character is ignored) they appear to the left of the caret, only lengthscale numbers are accepted, any other number typed is ignored as the integer portion is full. Any time the user types the decimal point the caret moves to the right side of the decimal point. The following numbers typed are shown in the decimal part, only scale numbers are considered any other number typed is ignored as the decimal portion is full. Additionally, thousand separators should appear as the user types numbers left to the decimal point.

Invoking a getValue() method on the component should yield the BigDecimal representing the number just entered.

I also want to be able to use the component as a Cell editor in a JTable without having to codit twice.

I’ve never created my own Swing component; I’ve barely used the standard ones. So I would appreciate any good tutorial/info/tip on creating the component described. This is the only thing I've got so far.

Thanks in advance.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not that hard, and I won't bother posting an example as you'll probably get it in your cross-post/s

http://stackoverflow.com/questions/2511270/advice-welcomed-on-creating-my-own-swing-component
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martin, please Be Forthright When Cross Posting To Other Sites.
 
Martin Mutilva
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok Rob. How can I delete this post then?
Thanks
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no need to delete any post. Just post a link to the same post on other forums next time, like Michael has done for you this time. And do the same for the other forums - post links to your posts here.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!