JText Field

If I am assigning a value to a Jtextfield in a method

JTextField curProject = new JTextField(20);
curProject.setText(currentProject.getName());

but now I want to add the textfield to my panel for my dialog
right now I have

final JTextField selProject = new JTextField(20);
        selProject.setEnabled(false);

How would I assign curProject to selProject?  

jkteaterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
You mean assign the text?
selProject.setText(curProject.getText());

Open in new window

jkteaterAuthor Commented:
I am getting the value for curProject in this method

private void showProjectSelectDialog() {
      EdiSelectProjectDialog ar = new EdiSelectProjectDialog(this, session, appReg);
        ar.setModal(true);
        ar.setVisible(true);
        EdiProject newProject = ar.getSelectedProject();
        if (newProject != null) {
              currentProject = newProject;
              JTextField curProject = new JTextField(20);
              curProject.setText(currentProject.getName());
             
        }
        else {
              System.out.println("No Project\n");
        }
   }

But I am trying to take that value and add it to my panel in a seperate method

private JPanel currentItems(){
        
        
        
        //JLabel eLabel = new JLabel("Current Project");
        curProjectLabel = new JLabel();
        cur3DTransLabel = new JLabel();
        cur2DTransLabel = new JLabel();
        curEmailLabel = new JLabel();
        
        final JTextField selProject = new JTextField(20);
        selProject.setText(curProject.getText());

        selProject.setEnabled(false);

But curProject can not be resolved
CEHJCommented:
The JTextField object should not be local to the method. Make it an instance variable then you won't have a problem accessing it in the same class
private JTextField curProject = new JTextField(20);
private void showProjectSelectDialog() {
      EdiSelectProjectDialog ar = new EdiSelectProjectDialog(this, session, appReg);
        ar.setModal(true);
        ar.setVisible(true);
        EdiProject newProject = ar.getSelectedProject();
        if (newProject != null) {
              currentProject = newProject;
              curProject.setText(currentProject.getName());
        }
        else {
              System.out.println("No Project\n");
        }
   }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
for_yanCommented:

>But I am trying to take that value and add it to my panel in a seperate method

But in this method below you don't have any JPnel and you are not abfding anything to it.

It should be something like this:

YOu proabbly also want to define sopme layout manager for this panel:

private JPanel currentItems(){
         
         
         JPanel p = new JPanel();
        //JLabel eLabel = new JLabel("Current Project");
        curProjectLabel = new JLabel();
        cur3DTransLabel = new JLabel();
        cur2DTransLabel = new JLabel();
        curEmailLabel = new JLabel();
         
        final JTextField selProject = new JTextField(20);
        selProject.setText(curProject.getText());

        selProject.setEnabled(false);
   p.add(curProjectLabel );
  p.add9 cur3DTransLabel );
...
  p.add(selProject());
   return p;

}

Open in new window


CEHJCommented:
:)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.