- 浏览: 59957 次
- 性别:
- 来自: 深圳
最新评论
-
zhylandroid:
...
JTable( 放在JScrollPane中 )中加入一行后, 然后让其获得焦点且滚动条自动下来 -
dkeagle:
太感谢了,太有用了,在网上查了两天资料了...
JTable( 放在JScrollPane中 )中加入一行后, 然后让其获得焦点且滚动条自动下来
Java Swing程序不像J2EE程序那样有框架有模式可遵,反倒显得很自由无所拘束,但如些一来反而显得程序代码杂乱无章,如果只是写个示例程序的话倒也无所谓,但随着代码的增多或过段时间在回首时就发现代码很不容易看懂,不以维护。我虽无大型Swing程序的经验,但平素喜爱用Swing写写工具程序以练练手,因此我以下是我的经验总结。下面以些图来表示
一个桌面级程序必然是以一个主界面展开的,在Swing中这个主界面是派生自JFrame的,其中有菜单、工具栏、状态栏、内容面板(contentPanel)和一些相应的按钮,这些界面元素即可以派生自某个类或调用Swing的现成类,但最后总要添加到界面中,而为了与用户交互,控件要和一个实现了Action接口的类绑定,因此在界面层中我分别实例化了ActionsManager和Functions对象,我专门写了一个ActionsManager类的用以管理程序中所有的Action接口的类,通过键值对集合把某个控件的动作与相应的控件绑定,当然你可能会觉得这很无聊,还不如在构造控件时直接将动作与之绑定就可以了,但这样做时很没有重复性,如果某个动作即要被按钮实现又要被菜单实现,还要被工具栏实现的话就要重复写三次代码,如果还要考虑其禁用与否就更麻烦了,因此我干脆将动作类统统封装在一个集合中统一调用,比如如下的代码
public class LoginActions { private MainPanel mainPanel; private LoginManager loginManager; private Map<String,LoginAction> mapActions; public LoginActions() { mapActions = new HashMap<String,LoginAction>(); new LoginAction("新建(N)","image/newfile.gif","image/tbnew.png",KeyEvent.VK_N,"ctrl N","new"){ public void actionPerformed(ActionEvent e) { mainPanel.newFile(); } }; new LoginAction("打开(O)...","image/open.gif","image/tbopen.png",KeyEvent.VK_O,"ctrl O","open"){ public void actionPerformed(ActionEvent e) { mainPanel.openFromFile(); } }; new LoginAction("保存(S)","image/save.gif","image/tbsave.png",KeyEvent.VK_S,"ctrl S","save"){ public void actionPerformed(ActionEvent e) { if(loginManager.isModifyFlag()) mainPanel.saveToFile(false); } }; new LoginAction("另存为(A)...",null,null,KeyEvent.VK_A,null,"saveas"){ public void actionPerformed(ActionEvent e) { if(loginManager.isModifyFlag()) mainPanel.saveToFile(true); } }; new LoginAction("导出(E)...",null,"image/tbexport.png",KeyEvent.VK_E,null,"export"){ public void actionPerformed(ActionEvent e) { mainPanel.exprotFile(); } }; new LoginAction("退出(X)",null,"image/tbexit.png",KeyEvent.VK_X,"ctrl alt X","exit"){ public void actionPerformed(ActionEvent e) { mainPanel.ExitApplication(); } }; new LoginAction("复制(C)","image/copy.gif",null,KeyEvent.VK_C,"ctrl C","copy"){ public void actionPerformed(ActionEvent e) { mainPanel.bottomPanel.editMenuCopy(); } }; new LoginAction("粘贴(P)","image/paste.gif",null,KeyEvent.VK_P,"ctrl V","paste"){ public void actionPerformed(ActionEvent e) { mainPanel.bottomPanel.editMenuPaste(); } }; new LoginAction("剪切(X)","image/cut.gif",null,KeyEvent.VK_X,"ctrl X","cut"){ public void actionPerformed(ActionEvent e) { mainPanel.bottomPanel.editMenuCut(); } }; new LoginAction("清除输入(R)",null,null,KeyEvent.VK_R,null,"reinput"){ public void actionPerformed(ActionEvent e) { mainPanel.bottomPanel.resetInput(); } }; new LoginAction("新增分类(A)",null,null,KeyEvent.VK_A,null,"addType"){ public void actionPerformed(ActionEvent e) { mainPanel.showTypeDlg(true); } }; new LoginAction("删除分类(D)",null,null,KeyEvent.VK_D,null,"delType"){ public void actionPerformed(ActionEvent e) { mainPanel.deleteType(); } }; new LoginAction("修改分类(M)",null,null,KeyEvent.VK_M,null,"modifyType"){ public void actionPerformed(ActionEvent e) { mainPanel.showTypeDlg(false); } }; new LoginAction("新增记录(D)",null,null,KeyEvent.VK_D,null,"addLogin"){ public void actionPerformed(ActionEvent e) { mainPanel.bottomPanel.addLogin(); } }; new LoginAction("删除记录(E)",null,null,KeyEvent.VK_E,null,"delLogin"){ public void actionPerformed(ActionEvent e) { mainPanel.bottomPanel.deleteLogin(); } }; new LoginAction("修改记录(O)",null,null,KeyEvent.VK_O,null,"modifyLogin"){ public void actionPerformed(ActionEvent e) { mainPanel.bottomPanel.modifyLogin(); } }; new LoginAction("查找(F)","image/tbfind.png",null,KeyEvent.VK_F,null,"findLogin"){ public void actionPerformed(ActionEvent e) { mainPanel.rightPanel.find(); } }; new LoginAction("转至地址(L)",null,null,KeyEvent.VK_L,null,"goURL"){ public void actionPerformed(ActionEvent e) { mainPanel.bottomPanel.goUrl(); } }; new LoginAction("刷新(U)","image/refresh.gif","image/tbudpate.png",KeyEvent.VK_U,null,"refresh"){ public void actionPerformed(ActionEvent e) { mainPanel.updatePanelUI(); } }; new LoginAction("程序设置(S)...","image/setup.gif","image/tbOption.png",KeyEvent.VK_S,null,"setup"){ public void actionPerformed(ActionEvent e) { mainPanel.showSetupDlg(); } }; new LoginAction("关于(A)...","image/about.gif","image/tbHelp.png",KeyEvent.VK_A,null,"about"){ public void actionPerformed(ActionEvent e) { mainPanel.showAboutDlg(); } }; } public Action getAction(String command) { return mapActions.get(command); } public void setMainPanel(MainPanel mainPanel) { this.mainPanel = mainPanel; } public void setLoginManager(LoginManager loginManager) { this.loginManager = loginManager; } abstract class LoginAction extends AbstractAction{ public LoginAction(String name,String icon,String bigIcon,int memKey,String stroke,String command) { this.putValue(NAME, name); if(icon!=null) this.putValue(Action.SMALL_ICON, new ImageIcon(this.getClass().getClassLoader().getResource(icon))); else this.putValue(Action.SMALL_ICON, new ImageIcon(this.getClass().getClassLoader().getResource("image/mnuNullIcon.gif"))); if(bigIcon!=null) this.putValue(Action.LARGE_ICON_KEY, new ImageIcon(this.getClass().getClassLoader().getResource(bigIcon))); if(memKey!=0) this.putValue(Action.MNEMONIC_KEY, memKey); if(stroke!=null) this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(stroke)); this.putValue("command", command); mapActions.put(command, this); } } }
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Greentea107/archive/2010/11/04/5988178.aspx
发表评论
-
curtain
2013-04-01 16:45 0curtain -
jlayer
2013-03-26 18:13 0jlayer pane. -
swing网站
2013-03-01 15:44 0(2009年4月2日更新) 最近在网上找到了一些比 ... -
aasss
2012-08-03 18:09 0aasss -
关于swing的文章
2012-07-30 15:50 0http://blog.csdn.net/mylxiaoyi/ ... -
vista button
2012-06-12 20:14 0import java.awt.AlphaComposite; ... -
database demo
2012-06-09 17:17 0kkk -
全局键盘事件
2012-06-06 10:19 1207KeyboardFocusManager manager = ... -
sssfw
2012-05-04 20:56 0http://www.byywee.com/page/M0/S ... -
swingtexiao
2012-05-04 20:00 0swingtexiao -
sss
2012-04-28 18:11 0sss -
使用annotation获取实体类注释
2012-04-11 18:57 0使用annotation获取实体类注释 -
自定义scrollbar
2012-04-11 18:49 0自定义scrollbar -
自定义绘制按钮
2012-04-11 18:47 0自定义绘制按钮 -
2012年4月6日
2012-04-06 18:48 02012年4月6日 -
批量缩放图片工具
2012-03-28 19:13 0挺好用 -
工作文档
2012-03-24 18:17 0import java.util.ArrayList; im ... -
test
2012-03-23 17:45 1tset -
A星算法
2012-03-23 15:20 1143A星算法 -
aasss
2012-03-21 18:58 1aaaaa
相关推荐
uipath操作版本19.4.4,如果不是这个版本可以尝试修改project.json文件
Ctrl +单击文件夹项目-在选项卡中打开所有书签Alt +单击Bookmakr项目-打开并删除版本0.5.1添加URL显示添加选项页添加删除和重命名文件夹Mod编辑和删除UI Mod搜索框和Search Item UI Ver 0.5 0添加快捷键快捷键。 ...
SwiftUI LazyVGrid和LazyHGrid 自定义对齐。1、垂直网格容器LazyVGrid。2、网格容器GridItem。3、生产数组 var gridData: [Int] { data.count%2 == 1 ? data.dropLast() : data }
listview中,单个ITEM中的动画播放与控制,可暂停,不会错位,点击执行动画,点击暂停动画
UI库,包含大部分MFC控件,带源码,在6.0下编译通过
2. On the landing page, Dashboard, click on the Work items menu item. Scrape the data in all the pages of the table, page by page, ensuring error handling and recovery. 3. For each page: - Filter the ...
包括Android布局,弹窗,配色,单击事件,UI,精美炫酷的activity切换动画和空间动画,是新手必备的源码,内含相关的Dome 25件。 - - 文件夹 PATH 列表 卷序列号为 4E8D-6931 C:. │ .txt │ Android-UI-新手必备...
Unity UGUI动态生成N个Item自动排列
Android为ListView添加圆角边框效果,安卓UI设计的例子,默认情况下ListView的外框是直角的,也就是大家习惯的样式,但为了美化更突出,或者与你的应用风格更吻合,有时候可能修饰成圆角边框,本例子就是实现了这一...
这是公司给我的UI培训项目 包含 常用UI组件的使用 在 EditText下弹出历史记录 活用ListView的Adapter 获取 ListView、GridView的Item内部的组件的内容 还有一些 其他的使用 总之 对AndroidUI开发 有很大的帮助
Android13 删除SystemUI状态栏中的电池图标&删除长按设置图标中电池快捷图标.patch
正版购买和预览地址 https://themeforest.net/item/brunette-responsive-bootstrap-4-admin-powerful-ui-kit/23158239
The Scroll View Extensions drastically extend the utility of the Unity UI Scroll Rect. Smooth and eased snapping (works great whether dragging using touch, mouse or scroll wheel) and user input ...
整理过的 CarouselDemo,修改了 Carouseitem 类 创建了 CarouseitemBase,item继承base,
Programmatically animated scroll to any item. Items can be grouped into categories, with event dispatched as categories change. Items filterable by user-specified tags. Items aware of their in-...
微信小程序之侧栏菜单,微信UI界面设计范例。在一些微信商城小程序中,一般都会有分类页面,可以给用户快速找到相关的商品,设计开发成如下图所示的效果,原理是使用了左右两个盒子,左盒子使用标准流,右盒子使用...
实现GridView的横向滑动,默认为纵向滑动,主要目标实现GridView中两个或多个相邻item的合并效果,满足项目的UI设计,同时解决了item选中放大被其他item遮挡的问题;用法简单,一目了然,可供参考
macOS SwiftUI LazyVGrid和LazyHGrid源码。1、垂直网格容器LazyVGrid。2、网格容器GridItem。3、生产数组 var gridData: [Int] { data.count%2 == 1 ? data.dropLast() : data }
FancyScrollView是一个可以实现复杂灵活动画效果的通用UI滑动列表组件,可以帮助开发者快速实现表现力丰富的UI滑动列表。
您可以将任何预先构建的UI元素添加到设计中。选项很多,包括按钮,徽章,小部件,时间轴,模态,进度条等元素。它们都可以进行自定义,以确保它们符合或与仪表板的其他部分形成对比。 演示地址 ...