HELP ME !
Dear people !
I faced with a "strange" problem !
Here is a code :
public class Test implements ActionListener{
public JTextPane picture;
public JPanel leftHalf;
JSplitPane splitPane;
/** Creates a new instance of Test */
public Test() {
leftHalf = new JPanel();
JScrollPane listScrollPane = new JScrollPane(leftHalf);
leftHalf.add(createButton());
picture = new JTextPane();
JScrollPane pictureScrollPane = new JScrollPane(picture);
picture.setText("This is a TEXT");
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,listScrollPane, pictureScrollPane);
splitPane.setPreferredSize(new Dimension(600, 450));
splitPane.setDividerLocation(300);
Dimension minimumSize = new Dimension(100, 50);
listScrollPane.setMinimumSize(minimumSize);
pictureScrollPane.setMinimumSize(minimumSize);
}
public JSplitPane getSplitPane() {
return splitPane;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
final Test myTest = new Test();
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
myTest.createAndShowGUI();
}
});
}
public void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("TITLE");
//Create Menu
JMenuBar menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
JMenu menu = new JMenu("Optiuni");
menu.setMnemonic(KeyEvent.VK_O);
menuBar.add(menu);
//Create Submenu
JMenuItem menuItem;
menuItem = menu.add("Calculation");
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK));
menuItem.setMnemonic(KeyEvent.VK_C);
menuItem.setActionCommand("calculatie");
menuItem.setActionCommand("compute");
menuItem.addActionListener(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Test Test = new Test();
frame.add(Test.getSplitPane());
//Display the window.
frame.pack();
frame.setVisible(true);
}
//setting the action
public void actionPerformed(ActionEvent e) {
if("compute".equals(e.getActionCommand()))
updatePane();
if("write".equals(e.getActionCommand()))
updatePane();
}
//action to perform
private void updatePane() {
String text = picture.getText();
picture.setText("! This is another TEXT !");
System.out.println(text);
}
//create a button
private Component createButton() {
JPanel panel = new JPanel();
JButton button = new JButton("COMPUTE");
button.addActionListener(this);
button.setActionCommand("write");
panel.add(button);
return panel;
}
}
The problem is:
- actioning the left pane button, the rightpane is updated !
- actioning the "menu" the right panel isn't updated !
Please HELP ME to have the same action with both methods mentioned above !

