Topic: 我的程序组件怎么显示不出来???帮帮我啊!!急!急!急! |
Print this page |
1.我的程序组件怎么显示不出来???帮帮我啊!!急!急!急! | Copy to clipboard |
Posted by: cherryzxp Posted on: 2006-05-31 14:37 import java.awt.*; import java.awt.event.*; import java.util.Enumeration; import javax.swing.*; import javax.swing.border.CompoundBorder; import javax.swing.border.EmptyBorder; import javax.swing.border.LineBorder; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.MutableTreeNode; import javax.swing.tree.TreeModel; public class MessageManagement extends JFrame implements ActionListener, TreeSelectionListener{ /** * */ static final int AUTO_RESIZE_SUBSEQUENT_COLUMNNS = 0; /** * */ /** * this part about JMenu. */ JMenuBar menubar = new JMenuBar(); JMenu menu1; JMenu menu2; JMenuItem menuItem11; JMenuItem menuItem21; JTree jtree; JLabel label; JTextArea textArea; JTable table; public MessageManagement() { jtree = new JTree(creatTreeModel()); jtree.setBorder(new EmptyBorder(4, 4, 4, 4)); jtree.addTreeSelectionListener(this); JPanel leftPanel = new JPanel(new BorderLayout()); leftPanel.setBorder( new CompoundBorder(new LineBorder(new Color(192, 192, 192), 4), new LineBorder(new Color(160, 120, 30), 3))); leftPanel.add(jtree, BorderLayout.CENTER); JSplitPane right = new JSplitPane(JSplitPane.VERTICAL_SPLIT); right.setTopComponent(creatJTable()); right.setBottomComponent(creatPane()); JSplitPane itemPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); itemPane.setLeftComponent(new JScrollPane(jtree)); itemPane.setRightComponent(right); this.getContentPane().add(itemPane); pack(); setJMenuBar(creatMenu()); Dimension screen=Toolkit.getDefaultToolkit().getScreenSize(); setSize(screen.width,screen.height); setTitle("信息管理系统"); setVisible(true); } public JMenuBar creatMenu() { menu1 = new JMenu("文件(F)"); menu1.setMnemonic('F'); menu2=new JMenu("帮助(H)"); menu2.setMnemonic('H'); menuItem11=new JMenuItem("退出(X)"); menuItem11.setMnemonic('X'); menu1.add(menuItem11); menuItem21=new JMenuItem("关于messageManagement(A)"); menuItem21.setMnemonic('A'); menu2.add(menuItem21); menubar.add(menu1); menubar.add(menu2); menuItem11.addActionListener(this); menuItem21.addActionListener(this); return menubar; } /** * */ public TreeModel creatTreeModel(){ DefaultMutableTreeNode root = new DefaultMutableTreeNode("192.168.1.7"); root.add(creatNode1()); root.add(creatNode2()); root.add(creatNode3()); root.add(creatNode4()); root.add(creatNode5()); root.add(creatNode6()); return new DefaultTreeModel(root); } public MutableTreeNode creatNode1(){ DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("收件箱"); return node1; } public MutableTreeNode creatNode2(){ DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("发件箱"); return node2; } public MutableTreeNode creatNode3(){ DefaultMutableTreeNode node3 = new DefaultMutableTreeNode("收藏夹"); return node3; } public MutableTreeNode creatNode4(){ DefaultMutableTreeNode node4 = new DefaultMutableTreeNode("待处理"); return node4; } public MutableTreeNode creatNode5(){ DefaultMutableTreeNode node5 = new DefaultMutableTreeNode("公告通知"); return node5; } public MutableTreeNode creatNode6(){ DefaultMutableTreeNode node6 = new DefaultMutableTreeNode("会议记录"); return node6; } public JPanel creatPane(){ JPanel panel=new JPanel(); label=new JLabel("收件人: "+"发件人: "+"主题: "); textArea=new JTextArea(); panel.add(label,"North"); panel.add(new JScrollPane(textArea),"Center"); return panel; } public JTable creatJTable(){ String[] header={"收件人","发件人","主题","日期"}; Object[][] data={null}; table=new JTable(data,header); table.setRowHeight(20); table.setAutoResizeMode(AUTO_RESIZE_SUBSEQUENT_COLUMNNS); return table; } /** * @param args */ public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); Font font=new Font("JFrame",Font.PLAIN,14); Enumeration en=UIManager.getLookAndFeelDefaults().keys(); while(en.hasMoreElements()){ Object key=en.nextElement(); if(UIManager.get(key)instanceof Font) UIManager.put(key,font); } new MessageManagement(); } public void actionPerformed(ActionEvent e) { if(e.getSource()==menuItem11){ dispose(); System.exit(0); } else if(e.getSource()==menuItem21){ JOptionPane.showMessageDialog(null,"版权所有(java编程小组)06.5.23"); } } public void valueChanged(TreeSelectionEvent arg0) { } } |
2.Re:我的程序组件怎么显示不出来???帮帮我啊!!急!急!急! [Re: cherryzxp] | Copy to clipboard |
Posted by: JavaandC Posted on: 2006-06-01 09:30 把这个方法修改一下就可以了 。 public JTable creatJTable(){ String[] header={"收件人","发件人","主题","日期"}; Object[][] data={}; //不要设置成null Object[][] data={null}; table=new JTable(data,header); table.setRowHeight(20); table.setAutoResizeMode(AUTO_RESIZE_SUBSEQUENT_COLUMNNS); return table; } |
3.Re:我的程序组件怎么显示不出来???帮帮我啊!!急!急!急! [Re: cherryzxp] | Copy to clipboard |
Posted by: cherryzxp Posted on: 2006-06-01 23:18 谢谢了!!太高兴了!! |
4.Re:我的程序组件怎么显示不出来???帮帮我啊!!急!急!急! [Re: cherryzxp] | Copy to clipboard |
Posted by: cherryzxp Posted on: 2006-06-01 23:19 谢谢了!!太高兴了!! |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |