Solved

Once mo about text field

Posted on 2011-02-24
57
295 Views
Last Modified: 2012-05-11
Let's leave behind two previous question because they need much more time for me to study answers.
This question only about simple setting string value from PMDS class to DCC class into jTextField1.
As I understood now it doesn't need to have any action listener for just setting text from string eurusd_bid into textfield with the command - setText(), but it doesn't appear on the screen, but visible on redirected output window.
Please advice
if ("EUR/USD".equalsIgnoreCase(symbol.trim())) {
                    bid = bidPx;
                    eurusd_bid = String.valueOf(bid);

                    DecisionCenterControl.getInstance().eurUSD_bid_TextField();

                    System.out.println("   EUR/USD  string bid   " + eurusd_bid);

Open in new window

jTextField1.setBounds(new Rectangle(505, 40, 95, 40));
        jTextField1.setFont(new Font("Lucida Grande", 1, 10));
............
    public void eurUSD_bid_TextField() {

        jTextField1.setText(eurusd_bid);
    }

Open in new window

0
Comment
Question by:gbcbr
  • 32
  • 24
57 Comments
 
LVL 92

Expert Comment

by:objects
ID: 34977396
are you sure you are updating the rignt variable.
need to see more of the gui code to see what the problem is
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34977399
Can you explain in more detail your environment; what means "it doesn't appear on the screen, but visible on redirected output window." ?
And is this something you want this way, or you have it this way?
0
 

Author Comment

by:gbcbr
ID: 34977410
>> are you sure you are updating the rignt variable.

>> what means "it doesn't appear on the screen, but visible on redirected output window." ?

DCC.tiff
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 47

Expert Comment

by:for_yan
ID: 34977423
But where do you pass string DecisionCenterControl.getInstance().eurUSD_bid_TextField();
There is no argument?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34977430
where d you get this string  eurusd_bid   in  jTextField1.setText(eurusd_bid)it should be

public void eurUSD_bid_TextField(eurusd_bid) {

        jTextField1.setText(eurusd_bid);
    }
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34977438
So you method shoul be defined this way:
public void eurUSD_bid_TextField( String eurusd_bid) {

        jTextField1.setText(eurusd_bid);
    }

and you should call it with the actial string as argument:

  DecisionCenterControl.getInstance().eurUSD_bid_TextField(eurusd_bid);


0
 
LVL 47

Expert Comment

by:for_yan
ID: 34977445
If those are two different classes then you should pass the string  to print on the textfield through the parameter, otherwise
how would it get the actual string to print.
0
 

Author Comment

by:gbcbr
ID: 34977448
I try this already from the beginning, same result
public void eurUSD_bid_TextField(String eurusd_bid){

//    public void eurUSD_bid_TextField() {

        jTextField1.setText(eurusd_bid);
    }

Open in new window

try {

                if ("EUR/USD".equalsIgnoreCase(symbol.trim())) {
                    bid = bidPx;
                    eurusd_bid = String.valueOf(bid);
    //              DecisionCenterControl.getInstance().eurUSD_bid();
                    DecisionCenterControl.getInstance().eurUSD_bid_TextField(eurusd_bid);

Open in new window

0
 

Author Comment

by:gbcbr
ID: 34977462
this is the reason of this question, it must to appear, but not
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34977465
but they both should have something inside parentheses.

This is the definition of the method:

  public void eurUSD_bid_TextField(String eurusd_bid) {

        jTextField1.setText(eurusd_bid);
    }


This is how you would use this mehod:

String eurusd_bid = "123.5";
 DecisionCenterControl.getInstance().eurUSD_bid_TextField(eurusd_bid);

Onle then you may hope to see "123.5" in your textfiled




0
 
LVL 47

Expert Comment

by:for_yan
ID: 34977473
It is all strange it should not even compile if you declare method without parameter and then
use it with parameter
0
 

Author Comment

by:gbcbr
ID: 34977490
String eurusd_bid printed well as a string in output window as you can see on screenshot.
If I will make it manually >> String eurusd_bid = "123.5";
What is difference, but I'll try
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34977503
That is how it works normally:

in one class, say class A,  you have the value of the String, say

String s = "abc";

In another class say, class B,  you have instance jTextField of JTextField  and in that second class you will have a method

public void setTextFieldValue(String s){
jTextField.setText(s);
}

then somehwre in class A you may have the code:

B b = new B();
String s = "abc";

b.setTextFieldValue(s);

then the text "abc" kind of "sent from" class A will appear in the TextFiled
in class B. But you need to pass this string as parameter.

Any questions? let me know





0
 

Author Comment

by:gbcbr
ID: 34977511
DCC2.tiff
@objects
>>need to see more of the gui code to see what the problem is
please find attached class DCC
DecisionCenterControl.java
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34977541
Now your DCC class has correct method
----------------------
      public void eurUSD_bid_TextField(String eurusd_bid){

        jTextField1.setText(eurusd_bid);
    }
-------------------------------------------

So how do you use this method in your PMDS class?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34977550
If you do not see this text appear in TextField, add printout:

      public void eurUSD_bid_TextField(String eurusd_bid){
      System.out.println("  .._bid: " + eurusd_bid);
        jTextField1.setText(eurusd_bid);
    }

Then you could see on your console  if parameter is passed to the method
0
 

Author Comment

by:gbcbr
ID: 34977557
yes, it passed
EUR/USD  string bid   1.38263
  .._bid: 1.38262
   EUR/USD  string bid   1.38262
  .._bid: 1.38267
   EUR/USD  string bid   1.38267
  .._bid: 1.38266
   EUR/USD  string bid   1.38266
  .._bid: 1.38262
   EUR/USD  string bid   1.38262

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 34977564
OK, and waht about TextField ?
0
 

Author Comment

by:gbcbr
ID: 34977566
why this method doesn't work?
 jTextField1.setText(eurusd_bid);
maybe it just invisible and need add setVisible?
0
 

Author Comment

by:gbcbr
ID: 34977584
>>waht about TextField ?
? you can see it in class
0
 

Author Comment

by:gbcbr
ID: 34977585
I'll be back in 3 hours
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34977590
No I mean does it change immediately after you see it printed?
So now I guess what you are saying that it does not.
It is probably because you are confused which textFiled has which name, let me see
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34977600

I guess you don't see this jTextField1 in your GUI
and why do you set Layout(null) - ? What does this mean?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34977615
This Layout stuff is very important - just one element
may be overlayed by another and you do not see it easily.
So why does it say setLayout(null).
I always use some Layout, I don't understand it

You see your puicture shows only 4 textfields, but in fact you have 5, i guess
jTextField1 is bbeyond the border - try to resize your window
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34977674
Any news about the fifth TextField which we do not see?
Let me know - I'm thinking about going home
0
 

Author Comment

by:gbcbr
ID: 34979508
I checked all names, there are OK.
It's some general problem, because no one parameter I can set in any jTextField from this method.
Even String value.
But at the same time I can set all these parameters directly.
jTextField1.setBounds(new Rectangle(515, 180, 430, 275));
        jTextField1.setFont(new Font("Lucida Grande", 1, 10));
        jTextField1.setLayout(null);
        jTextField1.setDoubleBuffered(true);
        
        jTextField2.setBounds(new Rectangle(620, 40, 95, 40));
        jTextField2.setOpaque(true);
        jTextField2.setBorder(BorderFactory.createTitledBorder("Ask"));
        jTextField2.setText("test text");

        jTextField3.setBounds(new Rectangle(730, 40, 95, 40));
        jTextField3.setToolTipText("Support 1");
        jTextField3.setBackground(new Color(255, 82, 82));
        jTextField3.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));

        jTextField4.setBounds(new Rectangle(840, 40, 95, 40));
        jTextField4.setEditable(false);
        jTextField4.setBackground(new Color(99, 255, 99));
        jTextField4.setToolTipText("Resistanse 1");
        jTextField4.setOpaque(true);
        jTextField4.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));

        jTextField5.setBounds(new Rectangle(950, 40, 95, 40));
        jTextField5.setBorder(BorderFactory.createTitledBorder(""));
..........................
    public void setTextFieldValue(String eurusd_bid) {

        System.out.println("  .._bid: " + eurusd_bid);
        if (eurusd_bid != null) {
            try {
                System.out.println(" 2 .._bid: " + eurusd_bid);

                jTextField1.setText(eurusd_bid);
                jTextField1.setBorder(BorderFactory.createTitledBorder("Bid"));
                jTextField2.setText(eurusd_bid);
                jTextField3.setText("eurusd_bid");
                jTextField4.setText(eurusd_bid);
                jTextField5.setText("test");
            } catch (Exception p) {
                p.printStackTrace();
            }
        }

Open in new window

DCC3.tiff
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34981554
What does this picture show?

I see only setting "test" in your program jTextField5.setText("test");
but there is also "text" and "ask" - when they are set?

And what you mean set all these parameters directly?
Do you see any Java error messages on the console?

You made simultaneously many changes - better to concentrate on one mystery
and do it stepwise.

So, exactly as I wrote you yesterday - it has to work.
The reason it does not is because you are not sure which buttnos you see
in which place. So return to yesterdays code, and if you don't see it on
jTextField1, try absolutely the same but with jTextFiel2, jTextFiled3, etc.

Another option is to chraete them in constructor
with "txt1" "txt2", etc written on them ffor testing.

But do all these testings logically one by one, it jsut has to work if you do
methodically stepwise







0
 
LVL 47

Expert Comment

by:for_yan
ID: 34981568
Do you have console to see the errors?
0
 

Author Comment

by:gbcbr
ID: 34981837
During your sleeping I work step by step, not
>>You made simultaneously many changes - better to concentrate on one mystery
and do it stepwise.
This is final result.
I'll tell you more, I create separate JFrame class CurrentRates to exclude any influence:
public class CurrentRates extends JFrame {
    private JTextField jTextField1 = new JTextField();
    private JTextField jTextField2 = new JTextField();
    private static final CurrentRates INSTANCE = new CurrentRates();

    public static CurrentRates getInstance() {
        return INSTANCE;
    }

    public CurrentRates() {
        try {
            jbInit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        this.getContentPane().setLayout(null);
        this.setSize(new Dimension(400, 300));
        
        jTextField1.setBounds(new Rectangle(40, 80, 100, 40));
        jTextField1.setSize(new Dimension(100, 40));
        jTextField1.setText("Field 1");
        
        jTextField2.setBounds(new Rectangle(210, 80, 100, 40));
        jTextField2.setSize(new Dimension(100, 40));
        
        this.getContentPane().add(jTextField2, null);
        this.getContentPane().add(jTextField1, null);
    }

    public void setTextFieldValue(String eurusd_bid) {

        System.out.println("  .._bid: " + eurusd_bid);
        if (eurusd_bid != null) {
            try {
                System.out.println(" 2 .._bid: " + eurusd_bid);

                jTextField2.setText(eurusd_bid);

            } catch (Exception p) {
                p.printStackTrace();
            }
        }
    }
}

Open in new window

PMDS:
if ("EUR/USD".equalsIgnoreCase(symbol.trim())) {
                    bid = bidPx;
                    eurusd_bid = String.valueOf(bid);

                    DecisionCenterControl.getInstance().setTextFieldValue(eurusd_bid);
                    CurrentRates.getInstance().setTextFieldValue(eurusd_bid);

Open in new window

Result: DCC4.tiff
As you can see all String values entered at jbInit method work in both DCC and CR classes, but from setTextFieldValue(String eurusd_bid) method nothing settled, despite of normal passing parameter eurusd_bid into this method in both classes DCC and CR.
As I told, it's some general mistake, but I don't understand where.
From the morning I tried 100's combinations with the same null result.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34982015
Do you see Java errors on the console?
Do you see normal Java Console, not RedirectOutput?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34982133
I'm afraid that printStackTrace() does not redirect correctly.
Add some System.out.println("Error " + p.toString()); into the catch loop, maybe we;ll see something
In general, believe me,  you cannot do real debugging  without  normal console.
All these stuff adds additional uncertainty to what is a process with many uncertainties anyway
 
0
 

Author Comment

by:gbcbr
ID: 34982137
RedirectOutput is a normal console view, it just redirect all messages from console into JFrame window.
If I have any error, I can think about what generate it and report here, but unfortunately it's no error messages, everything work perfect except of this b... textfields messages.
As you see I even try to set straight String in DCC
jTextField3.setText("eurusd_bid");
                jTextField4.setText(eurusd_bid);
                jTextField5.setText("test");

Open in new window

, not value of eurusd_bid, even this doesn't work.
Looks like this method - setTextFieldValue(String eurusd_bid) - can't set any parameters into jTextField, I tried different parameters, not only setText. Looks like it blind now.
0
 

Author Comment

by:gbcbr
ID: 34982166
no error printed
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34982167
It cannot be any mystery - it is always stupid mistake. Add System.println into the catch loop.
 
0
 

Author Comment

by:gbcbr
ID: 34982189
>>It cannot be any mystery - it is always stupid mistake.
100000% agree
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34982196
Can you post the code in such a way that I can compile it - at least part of it buut self sufficient?
0
 

Author Comment

by:gbcbr
ID: 34982209
which classes you want?
0
 

Author Comment

by:gbcbr
ID: 34982251
Main.java PMDS.java CurrentRates.java
check if it's enough
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34982338
No I of course don't have all those com.fxcm....

If you can strip it to barebone stuff without sthat specifics  and make sure it still does not set the textfiled,
then you can send it to me. If in the process it starts working you can
then identify the step which is the culprit - so I suggest that you start removing all dependencies,
which are not genereal - when you come to layout and njust 2-3 classes of general type wthout com.fxm, etc.
then send to me It is difiicult to find somthing just lookin at the code.
When compiling and running I'm sure we'll find
0
 

Author Comment

by:gbcbr
ID: 34982446
I can provide you access to my demo account, otherwise you can't get stream data and test this code. Just give me your private e-mail, Skype or whatever, so I'll not publish this data in public place. It's demo account with fake money, but anyway better don't live open access for everybody.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34982462
You know CurrentRates seems self-sufficient
Let me try
0
 

Author Comment

by:gbcbr
ID: 34982506
Anyway, I don't think that you can test it without stream data.
This is a key-point, to get into the field live data.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34982561
This works for me I see one box with Filed1, another box with 1.25 - try if these exact files (without a single change) if they work for you
UseCurrentRates.java
CurrentRates.java
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34982578
No, if you see the string before you use setText in one class with System.out.println, then it does not matter wher it came before - stream or no stream
0
 

Author Comment

by:gbcbr
ID: 34982752
Yes, this code works properly, as I suppose it should work.
Why mine not?
Looks exactly the same.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34982837
try adding your stuff gradullay to this code stewise - and checking if it works - you'll track the moment when it breaks.
0
 

Author Comment

by:gbcbr
ID: 34982869
what you mean gradually?
We have only one similar executing line >>jTextField2.setText(eurusd_bid);
In your case it works, in mine not.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34982883
Well, thats impossible - if so use these files istead of yours - rename the main class into yours and there you go - it works.
0
 

Author Comment

by:gbcbr
ID: 34982891
The difference only that you call >>
CurrentRates.getInstance().setTextFieldValue(eurusd_bid);
from the main method
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34982924
It works equally well from any place; check this code
UseCurrentRates.java
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34982934
Or even this way - without static String
UseCurrentRates.java
0
 

Author Comment

by:gbcbr
ID: 34982979
Yes, looks nice, I was expected this output in my code, Why I don't have it?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34982998
At this point it becomes a little metaphysical - you have exactly the same codes and they give differen results - that is impossible.
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 34983015
Compare two codes - you must see the difference
0
 

Author Comment

by:gbcbr
ID: 34983182
The biggest difference what I found is that in your code you don't create new class CR from the main method, just call the instance, but anyway it appear as visible with value of eurusd_bid. If I comment from my main
//        cr = new CurrentRates();
//        cr.setVisible(true);
this window doesn't appear at all.
Looks like you initiate this class by calling instance from the method, but I can't do it.
0
 

Author Comment

by:gbcbr
ID: 34983398
Let's drink 100 grams for solution.
I've commented from my main
//        cr = new CurrentRates();
//        cr.setVisible(true);
and add to CR/jbInit/this.setVisible(true);
and as soon new data arrive, it starts to appear into textfield2.
Now is my shift to sleep.
Thank you for the help!
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34983823
OK. Good it finally worked!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question