本帖最後由 luckiejacky 於 2013-9-8 17:19 編輯
1) Why the mainPanel2 within the TreeListener only refreshes when I click on the
root node, when I inject a custPanel directly into that mainPanel, it works ok
2) How do I get the source like e.getSource() from a mouse listener/tree listener.
e.getSource() == tcr doesn't work- package jewelleryMain;
- import GenericForm.GradientPanel;
- import GenericForm.TopPanel;
- import javax.swing.JFrame;
- /**
- *
- * @author Jacky
- */
-
-
- public class MainFrame2 extends javax.swing.JFrame implements Runnable {
- /**
- * Creates new form mainFrame
- */
-
- @SuppressWarnings("empty-statement")
- public MainFrame2() throws SQLException {
- db = new Database("jdbc:mariadb://localhost:3307/pos_crm");
- db.OpenConnection();
-
- initComponents();
-
- }
- Thread t;
-
-
- public void start()
- {
- t = new Thread(this);
- t.start();
- }
- public void stop()
- {
- t = null;
- }
- public void doSomething()
- {
- setTitle((new java.util.Date()).toString());
- }
- public void run() {
- while (t != null){
- doSomething();
- try {
- Thread.sleep(1000);
- } catch(InterruptedException ex) {
- }
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- @Override
- public void run() {
- try {
- new MainFrame2().setVisible(true);
- } catch (SQLException ex) {
- Logger.getLogger(MainFrame2.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- });
- }
-
- private Database db;
- private int custID;
- TopPanel topPanel;
- // End of variables declaration
- private void initComponents() throws SQLException {
- Container mainPanel = this.getContentPane();
- topPanel = new TopPanel("/images/topbar_Start.png");
- mainPanel.add(topPanel, BorderLayout.NORTH);
- centerPanel = new GradientPanel(color1, color2);
- GradientPanel TreePanel = new GradientPanel(color1, color2);
-
-
- JTree tree = null;
- crm = new DefaultMutableTreeNode("CRM");
- tcr = new DefaultMutableTreeNode("TCR");
- totalCustomer = new DefaultMutableTreeNode("Total Number of Customers");
- totalValueCustomer = new DefaultMutableTreeNode("Total Value of Customers");
- top25Customers = new DefaultMutableTreeNode("Total 25 Customers");
- top25StatusChange = new DefaultMutableTreeNode("Top 25 status change");
- addCustomer = new DefaultMutableTreeNode("加入客户");
- top25StatusChange = new DefaultMutableTreeNode("Top 25 status change");
- viewCustomer = new DefaultMutableTreeNode("显示客户");
- manageCustomer = new DefaultMutableTreeNode("管理客户");
- report = new DefaultMutableTreeNode("展示报告");
- administor = new DefaultMutableTreeNode("系统维护");
-
-
-
-
-
-
- tcr.add(totalCustomer);
- tcr.add(totalValueCustomer);
- tcr.add(top25Customers);
- tcr.add(top25StatusChange);
-
- crm.add(tcr);
- crm.add(addCustomer);
- crm.add(viewCustomer);
- crm.add(manageCustomer);
- crm.add(report);
- crm.add(administor);
-
- tree = new JTree(crm);
-
-
-
- TreePanel.add(tree);
-
- final DefaultTreeCellRenderer renderer =
- (DefaultTreeCellRenderer)(tree.getCellRenderer());
-
- renderer.setTextNonSelectionColor(Color.WHITE);
- renderer.setTextSelectionColor(Color.YELLOW);
- renderer.setOpaque(false);
-
-
- tree.setOpaque(false);
- tree.addTreeSelectionListener(new TreeSelectionListener() {
- @Override
- public void valueChanged(TreeSelectionEvent e) {
- ActionButtonsPanel btnPanel;
- try {
- btnPanel = new ActionButtonsPanel(db, 1);
- GenericCustomerPanel custPanel = new GenericCustomerPanel(db,-1);
- JSplitPane mainPanel2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, custPanel, btnPanel);
- mainPanel2.setDividerLocation(700);
- mainPanel2.setEnabled(false);
-
- centerPanel.add(mainPanel2);
-
- //centerPanel.repaint();
-
-
- } catch (SQLException ex) {
- Logger.getLogger(MainFrame2.class.getName()).log(Level.SEVERE, null, ex);
- }
-
-
- }
-
- } );
-
-
-
-
-
-
- JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, TreePanel, centerPanel);
-
- splitPane.setDividerLocation(200);
- splitPane.setDividerSize(2);
- splitPane.setEnabled(false);
-
-
- mainPanel.add(splitPane, BorderLayout.CENTER);
-
-
-
-
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setSize(1280, 1000);
- setVisible(true);
-
-
-
- }
- Color color1 = new Color(0,0,0);
- Color color2 = new Color(128,128,128);
- DefaultMutableTreeNode crm;
- DefaultMutableTreeNode tcr;
- DefaultMutableTreeNode totalCustomer;
- DefaultMutableTreeNode totalValueCustomer;
- DefaultMutableTreeNode addCustomer;
- DefaultMutableTreeNode top25Customers;
- DefaultMutableTreeNode top25StatusChange;
- DefaultMutableTreeNode viewCustomer;
- DefaultMutableTreeNode manageCustomer;
- DefaultMutableTreeNode report;
- DefaultMutableTreeNode administor;
-
-
-
- //Container mainPanel;
- //CreateCustomer createCust;
- protected GradientPanel centerPanel;
- // ActionButtonsPanel btnPanel;
-
- }
複製代碼 |