• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

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?  

0
jkteater
Asked:
jkteater
  • 3
1 Solution
 
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
 
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
 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now