Piet Souris wrote:I created a new JFrame application i NetBeans, dragged a JPanel into the frame
and called it 'PanelForNumericFieldnf1'.
Therewas one thing I had to do as well: I had to set the Layoutmanager of
this panel to 'FlowLayout'. I missed that in my earlier step-by-step description.
Right click on that panel, and in the pop-up menu choose 'Set Layout' and go
for 'FlowLayout'.
(for technical reasons I had to change the name to 'NumericField1').
Run this code, and you will see this NumericField appearing in the panel.
If you replace this panel with your 'card17', you should get the same
outcome.
One remark:
in your version of ' initMyOwnVariables()' I see:
'nf1' is now a local variable, not known outside of this method.
If you look at my code, you'll see I made that component a member variable.
Th advantage is is that I have this variable available everywhere in the code,
but whether that is necessary, I don't know. But for now it might be safest to do so.
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:hi rodolfo,
hmmm... it iseems that sofar I mispredicted nearly everything
about what I thought you had coded.
Let me put my assumptions about your code:
1) you have a frame, and in that frame you have a ContentPane
that uses a CardLayout.
2) there are (at least) 17 "cards" (JPanels) contained in this ContentPane.
3) at least card1 and card17 were created with the help of NetBeans GUI Builder.
For both panels you used a Null Layout.
4) card1 and card17 contain a JTextField, that should accept onlt digits up to a
maximum of 7
Am I right?
Let's assume it for now. The question is: how to replace these two JTextFields
with two NumericFields?
Well, leave everything as it is for the time being. In the method 'initMyOwnVariables()'
we will do this replacement. So here goes:
I assume that the JTextField in card1 is called 'jTextField1'.
You see how I add to and remove components from a JPanel.
My previous steps-plan was based on the idea that you used 'GroupLayout'
for every cardXX.
rodolfo tuble wrote:I tried the code above and no textfield appeared in the panel, I should also note that I am using a jlabel as a background image.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:(...)
Because if it's supposed to be a "numeric" check, it's wrong.
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:
Winston Gutkowski wrote:(...)
Because if it's supposed to be a "numeric" check, it's wrong.
It is indeed supposed to be a numeric check, and no, it is not wrong.
Please have a close look at the code I supplied.
What about a simple 'string.match("...")' for a check if string contains only digits?
@rodolfo
In this thread, and in your other thread about centering lines,
you used pretty advanced GUI stuff like document filters and printJobs.
So, if you are asking me how to add a JTextField to a JPanel, while I
have given quite some examples now of how to get a NumericField
into your panels, that I cannot help to think you mean something
different with this question.
So I have a request: can you zip your project (i.e. the folder that contains
all of your code, including possibly some other resources), put in on
Git, DropBox. Google Drive or similar, so that I can have a look at
what you have so far?
Piet Souris wrote:It is indeed supposed to be a numeric check, and no, it is not wrong.
Please have a close look at the code I supplied.
What about a simple 'string.match("...")' for a check if string contains only digits?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
rodolfo tuble wrote:(...)
I was hoping that there would be a way to move jtextfield up so that it would not be hidden behind my background image. Thank you once again
There are three kinds of actuaries: those who can count, and those who can't.
Winston Gutkowski wrote:(...)
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:hi rodolfo,
well, I think the end is near. It is quite a thing to replace
your textfields by these NumericFields, in the way described.
So I turned back to your original question about more than one
filter. I had tried this before, but I couldn't get it to work.
Yesterday evening I saw what I did wrong: I had only done
an override of the 'insert' method, but it turned out that java
uses the 'replace' method.
So, here is an updated class 'SizeAndDigitFilter', and you only
need to replace the filter of your original JTextField by an
instance of this class. I have included a demo how to do this.
I've tested it, but it seems okay.
There are three kinds of actuaries: those who can count, and those who can't.
So it takes a day for light to pass through this glass? So this was yesterday's tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|