2010/01/26
run Matlab in JAVA successful with Matlab 2009b
CLASSPATH:
.;E:\JAVA\jre6\lib\ext\QTJava.zip
JRE_HOME:
E:\JAVA\jre6\
MATLAB_JAVA
E:\JAVA\jre6
PATH
E:\program_files\miktex\miktex\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;E:\JAVA\jdk\bin;E:\program_files\3.2.2_gcc-4.3.0\bin;C:\Program Files\QuickTime\QTSystem\;F:\shortcuts;C:\Program Files\Common Files\Thunder Network\KanKan\Codecs;E:\program_files\matlab\bin;E:\program_files\matlab\runtime\win32
2010/01/25
Add item to a panel dynamically
One could add a node group to the main panel(Text Pane) by clicking "add group" button.
The class definition of the node group panel(JPanel) and the action listeners of "Add Group" button, "Remove" button are shown as following:
Class NodesGroupPanel:
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
* Displays and generates nodes.
*
* @author chenyang
*/
public class NodesGroupPanel extends JPanel {
private int newWidth = 512;
private int newHeight = 27;
private JLabel groupNrBt;
private JTextField node1Txt, node2Txt, stepTxt, x1Txt, x2Txt, y1Txt, y2Txt;
public NodesGroupPanel(int groupNr) {
super();
if (groupNr<10){ groupnrbt =" new">=10&&groupNr<100){ groupnrbt =" new">=100&&groupNr<1000){ groupnrbt =" new" groupnrbt =" new" node1txt =" new" node2txt =" new" steptxt =" new" x1txt =" new" x2txt =" new" y1txt =" new" y2txt =" new">
jButton5ActionPerformed of "Add Group" button:
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
jPanel6.setText(jPanel6.getText() + "\n\n");
NodesGroupPanel ngp = new NodesGroupPanel(nodesManager.getGroupCount() + 1);
jPanel6.add(ngp);
nodesManager.addToGroup(ngp);
// repaint
jPanel6.validate();
jPanel6.repaint();
// add item to jComboBox1 in remove panel
jComboBox1.addItem(nodesManager.getGroupCount());
}
jButton4ActionPerformed of "Add Group" button:
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
if (nodesManager.getGroupCount() > 0) {
removeNodeGroupDialog.setVisible(true);
}
}
%%%%%%%%%%%%%%
where removeNodeGroupDialog is shown as: And the "Remove" button on this Dialog acts as:
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
NodesGroupPanel ngp = nodesManager.removeNodesGroup(jComboBox1.getSelectedIndex() + 1);
if (ngp != null) {
jPanel6.remove(ngp);
jPanel6.validate();
jPanel6.repaint();
jComboBox1.removeItemAt(jComboBox1.getItemCount() - 1);
}
}