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?
 
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

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

Open in new window

0
 
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
0
 
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


0
 
CEHJCommented:
:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.