ARTICLE AD BOX
I have a JTextArea called premiseText. It is initialized with a default value and is setEditable(false). When I want User to change that value, I have a JButton called editPremise that, in that button's ActionPerformed, calls setEditable(true). I have another JButton that is setEnabled(false) but which is changed to setEnabled(true) inside that same ActionPerformed. That second button changes to being enabled as expected, but the JTextArea never becomes editable.
public class ConceptPanel extends JPanel { PrintManager pm = new PrintManager(); ConceptData data; Border raisedbevel = BorderFactory.createRaisedBevelBorder(); JPanel premisePanel; JButton updatePremiseButton; JLabel premiseLabel; JTextArea premiseText; JPanel premiseButtonPanel; public ConceptPanel (ConceptData inData) { data = inData; this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); createPremisePanel(); }//end constructor ConceptPanel public void createPremisePanel() { premisePanel= new JPanel(); premisePanel.setBorder(raisedbevel); premisePanel.setLayout(new BoxLayout(premisePanel, BoxLayout.LINE_AXIS)); updatePremiseButton = new JButton("UPDATE PREMISE"); premiseLabel = new JLabel("Briefly descripe the premise of this story: "); premiseLabel.setHorizontalAlignment(SwingConstants.LEFT); premisePanel.add(premiseLabel); premiseText = new JTextArea(1, 60); premiseText.setText(data.getPremise()); premiseText.setEditable(false); premisePanel.add(premiseText); JPanel premiseButtonPanel = new JPanel(); premiseButtonPanel.setLayout(new BoxLayout(premiseButtonPanel, BoxLayout.LINE_AXIS)); JButton cancelPremiseButton = new JButton("CANCEL"); cancelPremiseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent cancelEvent) { premiseText.setText(data.getPremise()); premiseText.setEditable(false); updatePremiseButton.setEnabled(false); } }); premiseButtonPanel.add(cancelPremiseButton); JButton editPremiseButton = new JButton("EDIT PREMISE"); editPremiseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent editEvent) { pm.print("edit Premise pressed"); premiseText.setEditable(true); updatePremiseButton.setEnabled(true); } }); premiseButtonPanel.add(editPremiseButton); updatePremiseButton.setEnabled(false); updatePremiseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent updateEvent) { String premiseString = premiseText.getText(); if(!premiseString.equals("") && !premiseString.equals(" ") && !premiseText.equals(null)) { pm.print("PremisePanel::updatePremiseButton action: premiseString is " + premiseString); data.setPremise(premiseString); //premiseText.setEditable(false); } updatePremiseButton.setEnabled(false); } }); premiseButtonPanel.add(updatePremiseButton); premisePanel.add(premiseButtonPanel); this.add(premisePanel); }//end createPremisePanel }//end class ConceeptPanelExplore related questions
See similar questions with these tags.
