Link to home
Start Free TrialLog in
Avatar of jkteater
jkteaterFlag for United States of America

asked on

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?  

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

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

Open in new window

Avatar of jkteater

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

>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


:)