Topic: 诚心求教:如何在JTABLE中部署JPOPUPMENU |
Print this page |
1.诚心求教:如何在JTABLE中部署JPOPUPMENU | Copy to clipboard |
Posted by: chenyoufan Posted on: 2005-09-08 17:19 迷茫中.....请问SWING开发中 如何在JTABLE中部署JPOPUPMENU? 需求为: JTABLE为显示数据库查询结果的表 当用鼠标右键选中JTABLE中的一行时,弹出JPOPUPMENU 类似JB中JDBTABLE所实现的效果 现在我遇到的问题是:JPOPUPMENU不能在JTABLE中显示 JPOPUPMENU.SHOW(E.GETCOMPONENT,E.GETX(),E.GETY()) 是不是JTABLE不属于COMPONENT?? 我是菜鸟,不要取笑我,各位高手请给点指点吧,谢谢 |
2.Re:诚心求教:如何在JTABLE中部署JPOPUPMENU [Re: chenyoufan] | Copy to clipboard |
Posted by: chenyoufan Posted on: 2005-09-27 12:42 没有人知道么?帖子已经放上来这么久了,没有哪位大哥能帮我一下的么 ? |
3.Re:诚心求教:如何在JTABLE中部署JPOPUPMENU [Re: chenyoufan] | Copy to clipboard |
Posted by: littledeer1974 Posted on: 2005-09-27 13:42 应该可以的吧? 你有没有写什么测试的代码? 如果有问题,可以拿上来,看看 光这么说,没有什么针对性,讨论也不好展开 |
4.Re:诚心求教:如何在JTABLE中部署JPOPUPMENU [Re: chenyoufan] | Copy to clipboard |
Posted by: chenyoufan Posted on: 2005-09-27 17:12 代码如下,个人认为貌似没有什么语法错误吧? 我还特地获取了鼠标点击时的坐标.............. 运行结果: JFRAME全屏显示时,不管点在哪里,菜单都不出现 JFRAME不是全屏显示时,鼠标点击在JTABLE的最右边一部分区域有显示, 不解................迷茫中.............高手赐教啊 package com.system.Gui; import java.awt.*; import javax.swing.*; import javax.swing.table.*; import javax.swing.table.AbstractTableModel; import javax.swing.table.TableModel; public class MainGui extends JFrame { TableList tablelist; String namestr; String schoolstr; String classstr; String subjectstr; JRootPane m_root; /* * 控件 */ JTextField m_Condition; JComboBox m_type; JButton m_btnSearch; public MainGui(){ jbInit(); } void jbInit(){ m_root = this.getRootPane(); m_root.setLayout(new BorderLayout()); this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); JPanel TopPanel = new JPanel(); TopPanel.setLayout(new FlowLayout()); JPanel BottomPanel = new JPanel(); BottomPanel.setLayout(new BorderLayout()); JPanel InforPanel = new JPanel(); InforPanel.setLayout(new FlowLayout()); JPanel NamePanel = new JPanel(); JLabel lbname = new JLabel("姓名:"); JLabel lbnamestr = new JLabel(namestr); NamePanel.add(lbname); NamePanel.add(lbnamestr); JPanel SubPanel = new JPanel(); JLabel lbsub = new JLabel("所教科目:"); JLabel lbsubstr = new JLabel(subjectstr); SubPanel.add(lbsub); SubPanel.add(lbsubstr); JPanel ScPanel = new JPanel(); JLabel lbsc = new JLabel("所在学校:"); JLabel lbscstr = new JLabel(schoolstr); ScPanel.add(lbsc); ScPanel.add(lbscstr); JPanel ClassPanel = new JPanel(); JLabel lbclass = new JLabel("任课班级"); JLabel lbclassstr = new JLabel(classstr); InforPanel.add(NamePanel); InforPanel.add(SubPanel); InforPanel.add(ScPanel); InforPanel.add(ClassPanel); TopPanel.add(InforPanel); tablelist = new TableList(this,10,10); JPanel SearchPanel = new JPanel(); SearchPanel.setLayout(new GridLayout(1,4,4,2)); JLabel lbcondition = new JLabel("查询条件:"); m_Condition = new JTextField(); m_type = new JComboBox(); m_btnSearch = new JButton("查询"); SearchPanel.add(lbcondition); SearchPanel.add(m_Condition); SearchPanel.add(m_type); SearchPanel.add(m_btnSearch); BottomPanel.add(tablelist,BorderLayout.CENTER); BottomPanel.add(SearchPanel,BorderLayout.SOUTH); m_root.add(TopPanel,BorderLayout.NORTH); m_root.add(BottomPanel,BorderLayout.CENTER); } } class TableList extends JScrollPane { FrameListener m_framelistener; public static int m_selectionRow; public static int m_selectionColumn; public TableList(MainGui maingui,final int row,final int col){ TableModel dataModel = new AbstractTableModel() { public int getColumnCount() { return row; } public int getRowCount() { return col;} public Object getValueAt(int row, int col) { return new Integer(row*col); } }; JTable table = new JTable(dataModel); table.setAutoResizeMode(0);//设置JTable是否及如何调整大小,以适应可用空间 this.getViewport().add(table); m_framelistener = new FrameListener(table); table.setRowSelectionAllowed(true); table.addMouseListener(m_framelistener); table.addKeyListener(m_framelistener); } } |
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 |