- 浏览: 830808 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (379)
- struts (5)
- hibernate (16)
- spring (16)
- ssh (20)
- MySQL (16)
- 数据库脚本 (2)
- DownLoad (1)
- GAE (5)
- Java (103)
- LoadRunner (2)
- VF (1)
- 学习资料 (24)
- 软件使用 (21)
- 通信类 (4)
- 生活 (3)
- J2ME (1)
- 心理学 (1)
- Linux (26)
- Android (3)
- Oracle (1)
- 面向对象概念&面试准备 (11)
- ExtJs (2)
- Google Map (1)
- Flex (47)
- 算法研究 (1)
- share (20)
- python (1)
- MongoDB (7)
- centos6 (13)
- C++ (8)
- DB2 (3)
- C# (1)
- 代码片段 (24)
- Lucene (2)
- php (1)
- NodeJS (1)
- Express (1)
最新评论
-
shua1991:
已阅,我表示同意。
Eclipse统计代码行数 -
nakedou:
写的不错,挺详细的
在CentOS中使用 yum 安装MongoDB及服务器端配置 -
sjp524617477:
好方法
Eclipse统计代码行数 -
simpletrc:
<script>ale ...
Java写到.txt文件,如何实现换行 -
csdn_zuoqiang:
Apache Ftp Server,目前是1.0.4,非常好的 ...
Apache FtpServer在64位系统下服务不能启动解决方法
package ui; import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Insets; import java.awt.Paint; import java.awt.Rectangle; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.Icon; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.plaf.basic.BasicTabbedPaneUI; /** * * @Description * @author zhangzuoqiang * @Email z.zuoqiang@gmail.com * @time 2012-3-22 上午10:36:21 * @do * @Modify */ public class EclipseTabbedPaneUI extends BasicTabbedPaneUI { private static final Color SELECTED_TAB_COLOR = new Color(10, 36, 106); private static final int TAB_MINIMUM_SIZE = 8; @Override protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { g.setColor(Color.GRAY); if (tabPlacement == BOTTOM) { g.drawLine(x, y + h, x + w, y + h); } // right g.drawLine(x + w - 1, y, x + w - 1, y + h); if (tabPlacement == TOP) { // And a white line to the left and top g.setColor(Color.WHITE); g.drawLine(x, y, x, y + h); g.drawLine(x, y, x + w - 2, y); } if (tabPlacement == BOTTOM && isSelected) { g.setColor(Color.WHITE); // Top g.drawLine(x + 1, y + 1, x + 1, y + h); // Right g.drawLine(x + w - 2, y, x + w - 2, y + h); // Left g.drawLine(x + 1, y + 1, x + w - 2, y + 1); // Bottom g.drawLine(x + 1, y + h - 1, x + w - 2, y + h - 1); } } protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect) { super.paintTab(g, tabPlacement, rects, tabIndex, iconRect, textRect); Rectangle rect = rects[tabIndex]; g.setColor(Color.black); // 绘制边框 g.drawRect(rect.x + rect.width - 16, rect.y + 4, 13, 12); g.drawLine(rect.x + rect.width - 16, rect.y + 7, rect.x + rect.width - 10, rect.y + 13); g.drawLine(rect.x + rect.width - 10, rect.y + 7, rect.x + rect.width - 16, rect.y + 13); g.drawLine(rect.x + rect.width - 15, rect.y + 7, rect.x + rect.width - 9, rect.y + 13); g.drawLine(rect.x + rect.width - 9, rect.y + 7, rect.x + rect.width - 15, rect.y + 13); } /** * Give selected tab blue color with a gradient!!. * * FIXME: with Plastic L&F the unselected background is too dark */ @Override protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { Color color = UIManager.getColor("control"); if (isSelected) { if (tabPlacement == TOP) { Graphics2D g2 = (Graphics2D) g; Paint storedPaint = g2.getPaint(); g2.setPaint(new GradientPaint(x, y, SELECTED_TAB_COLOR, x + w, y + h, color)); g2.fillRect(x, y, w, h); g2.setPaint(storedPaint); } } else { g.setColor(color); g.fillRect(x, y, w - 1, h); } } /** * Do not paint a focus indicator. */ @Override protected void paintFocusIndicator(Graphics arg0, int arg1, Rectangle[] arg2, int arg3, Rectangle arg4, Rectangle arg5, boolean arg6) { // Leave it } /** * We do not want the tab to "lift up" when it is selected. */ @Override protected void installDefaults() { super.installDefaults(); tabAreaInsets = new Insets(0, 100, 0, 0); selectedTabPadInsets = new Insets(0, 0, 0, 0); contentBorderInsets = new Insets(1, 0, 0, 0); } /** * Nor do we want the label to move. */ @Override protected int getTabLabelShiftY(int tabPlacement, int tabIndex, boolean isSelected) { return 0; } /** * Increase the tab height a bit */ @Override protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) { return fontHeight + 10; } @Override protected void layoutLabel(int arg0, FontMetrics arg1, int arg2, String arg3, Icon arg4, Rectangle arg5, Rectangle arg6, Rectangle arg7, boolean arg8) { super.layoutLabel(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); } /** * Selected labels have a white color. */ @Override protected void paintText(Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title, Rectangle textRect, boolean isSelected) { if (isSelected && tabPlacement == TOP) { g.setColor(Color.WHITE); } else { g.setColor(Color.BLACK); } if (title.length() > TAB_MINIMUM_SIZE) { title = "..." + title.substring(title.length() - TAB_MINIMUM_SIZE + 3, title.length()); textRect.x += 14; } // Font tabFont = new Font("微软雅黑", Font.BOLD, 11); // g.setFont(tabFont); g.drawString(title, textRect.x - 8, textRect.y + metrics.getAscent()); } @Override protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) { int taille = 0; String title = tabPane.getTitleAt(tabIndex); if (title.length() > TAB_MINIMUM_SIZE) { taille = SwingUtilities.computeStringWidth( metrics, (title.substring(title.length() - TAB_MINIMUM_SIZE, title.length()))) + 3; } else { taille = super.calculateTabWidth(tabPlacement, tabIndex, metrics); } return taille; } @Override protected void paintContentBorderTopEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) { if (selectedIndex != -1 && tabPlacement == TOP) { g.setColor(Color.GRAY); g.drawLine(x, y, x + w, y); } } @Override protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) { g.setColor(Color.GRAY); g.drawLine(x, y + h, x + w, y + h); } @Override protected void paintContentBorderLeftEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) { // do nothingx, y, x, y + h); } @Override protected void paintContentBorderRightEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) { // do nothing } @Override protected MouseListener createMouseListener() { return new CloseHandler(); } class CloseHandler extends MouseHandler { public CloseHandler() { super(); } public void mouseReleased(MouseEvent e) { int x = e.getX(); int y = e.getY(); int tabIndex = -1; int tabCount = tabPane.getTabCount(); for (int i = 0; i < tabCount; i++) { if (rects[i].contains(x, y)) { tabIndex = i; break; } } if (tabIndex >= 0 && !e.isPopupTrigger()) { Rectangle tabRect = rects[tabIndex]; y = y - tabRect.y; if ((x >= tabRect.x + tabRect.width - 18) && (x <= tabRect.x + tabRect.width - 8) && (y >= 5) && (y <= 15)) { tabPane.remove(tabIndex); } } } } }
package app; import java.awt.BorderLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.List; import java.util.Random; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.JTextField; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; import javax.swing.border.Border; import ui.EclipseTabbedPaneUI; public class Flipper extends JFrame implements ActionListener { /** * */ private static final long serialVersionUID = 1L; private final GridBagConstraints constraints; private final JTextField headsText, totalText, devText; private final Border border = BorderFactory.createLoweredBevelBorder(); private final JButton startButton, stopButton; private FlipTask flipTask; private JPanel top; private JTabbedPane tabbedPane; private JTextField makeText() { JTextField t = new JTextField(20); t.setEditable(false); t.setHorizontalAlignment(JTextField.RIGHT); t.setBorder(border); top.add(t, constraints); return t; } private JButton makeButton(String caption) { JButton b = new JButton(caption); b.setActionCommand(caption); b.addActionListener(this); top.add(b, constraints); return b; } private JTabbedPane makeTabbedPane() { JTabbedPane tPane = new JTabbedPane(); tPane.setTabPlacement(JTabbedPane.TOP); tPane.setBorder(null); tPane.setUI(new EclipseTabbedPaneUI()); tPane.addTab("库存页面库存页面库存页面", new JPanel()); tPane.addTab("库存页面库存页面", new JPanel()); tPane.addTab("库存页面", new JPanel()); tPane.addTab("库存页面库存页面库存页面", new JPanel()); tPane.addTab("库存页面库存页面", new JPanel()); return tPane; } public Flipper() { super("Flipper"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Make text boxes getContentPane().setLayout(new BorderLayout()); top = new JPanel(new GridBagLayout()); constraints = new GridBagConstraints(); constraints.insets = new Insets(3, 10, 3, 10); headsText = makeText(); totalText = makeText(); devText = makeText(); // Make buttons startButton = makeButton("Start"); stopButton = makeButton("Stop"); stopButton.setEnabled(false); tabbedPane = makeTabbedPane(); getContentPane().add(top, BorderLayout.NORTH); getContentPane().add(tabbedPane, BorderLayout.SOUTH); // Display the window. pack(); setVisible(true); } private static class FlipPair { private final long heads, total; FlipPair(long heads, long total) { this.heads = heads; this.total = total; } } private class FlipTask extends SwingWorker<Void, FlipPair> { @Override protected Void doInBackground() { long heads = 0; long total = 0; Random random = new Random(); while (!isCancelled()) { total++; if (random.nextBoolean()) { heads++; } publish(new FlipPair(heads, total)); } return null; } @Override protected void process(List<FlipPair> pairs) { FlipPair pair = pairs.get(pairs.size() - 1); headsText.setText(String.format("%d", pair.heads)); totalText.setText(String.format("%d", pair.total)); devText.setText(String.format("%.10g", ((double) pair.heads) / ((double) pair.total) - 0.5)); } } public void actionPerformed(ActionEvent e) { if ("Start" == e.getActionCommand()) { startButton.setEnabled(false); stopButton.setEnabled(true); (flipTask = new FlipTask()).execute(); } else if ("Stop" == e.getActionCommand()) { startButton.setEnabled(true); stopButton.setEnabled(false); flipTask.cancel(true); flipTask = null; } } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new Flipper(); } }); } }
发表评论
-
微信JS
2013-10-26 21:17 2039<div class="iteye-blog- ... -
ubuntu下MySQL用source命令导入sql文件出现乱码解决方法
2012-11-18 23:46 1483首先建立数据库的时候指明数据库编码如: CREA ... -
RandomAccessFile
2012-10-18 18:16 941public void run() { try { ... -
java中多种方式读文件
2012-10-18 16:53 925java中多种方式读文件一、多种方式读文件内容。1、按字节读取 ... -
FileChannelMain
2012-10-15 18:12 1072package scan; import java ... -
Apache FtpServer在64位系统下服务不能启动解决方法
2012-06-10 21:29 6799Apache FTPServer是一款用Java开发的 ... -
Java 集合类
2012-06-07 22:03 1563Java 集合类 1. 为什么要了解J ... -
short、int、long与byte之间的转换工具类
2012-05-31 11:05 4476/** * 各基础类型与byte之间的转换 * ... -
Linux Mint 13 配置JAVA 环境
2012-05-24 22:35 26190.1--下载 JAVA ... -
FatJar+Exe4j+Inno Setup 生成可执行的exe文件
2012-04-17 10:54 14241、fatjar 是Eclipse的一个免费的插件。它的 ... -
一个开源的高效全文检索框架(懂C语言可以进来研究下原理)
2012-04-07 23:03 1342示例地址: http://rbbs.sourcefor ... -
批量删除删除CVS文件夹
2012-04-06 16:11 2002@echo On @Rem C:/Users/XPan ... -
JPanel JTextField add Focus 获取焦点解决方案
2012-03-30 21:29 2979public class TabPagePanel ex ... -
JList List<E> Page 分页
2012-03-30 21:28 1730package view.retrieve.comps. ... -
JButton setAction的BUG
2012-03-23 10:53 1276今天在使用JButton的时候,想用setText()setI ... -
两个工具类
2012-03-17 21:27 863package com.retrieve.utils; ... -
两个工具类
2012-03-17 21:27 0package com.retrieve.utils; ... -
mysql、sqlserver、oracle分页,java分页统一接口实现
2012-03-13 17:56 0定义: pageStart 起始页,pageEnd 终止页, ... -
Invalid command: InetLoad::load
2012-03-06 16:41 1284Invalid command: InetLoad::load ... -
NIO: High Performance File Copying
2012-03-01 17:25 1148In a previous tip, I discussed ...
相关推荐
通过java swing 自定义JTabbedPane组件外观 演示自定义外观组件的方法
java swing jTabbedPane 自定义的U,包括(宽、高、点击放大、文本字体、背景颜色、选项卡间距等) 简单易懂带注释可直接运行
一个通过自定义JPanel来实现关闭按钮的JTabbedPane,因为使用了适配器去继承父类的方法,所以代码比较多但功能一般
关于jtabbedPane实现多程序集合
Java中JTabbedPane(选项卡)的用法实例,对于喜欢界面设计的朋友来说是个不错的例子!~
带关闭按钮可定制的JTabbedPane,首先解决了java自带的UI丑的不行的问题,然后附带了可关闭按钮,这个可关闭按钮,可以在添加标签时,自定义是否出现.该资源属于网络资源,谢谢作者的无私奉献.象征性的收1点积分,因为我的...
Java中的JTabbedPane无自带关闭按钮,Netbeans的jar包中实现了自带关闭功能,比自己编写控件方便多了。
一个简单的标签页实例
简单的swing tab用法.直接放在ide里就可以看到效果
JTabbedPane是Swing库提供的一个选项卡面板组件。它可以在图形界面中创建多个选项卡,并在用户点击不同选项卡时显示相应的内容。
有注释 下载后复制到eclipse中直接运行
本技巧提供JTabbedPane增强版本的代码,该代码允许开发人员将工具栏按钮添加到选项卡集的开头或结尾。
主要介绍了java Swing实现选项卡功能(JTabbedPane)实例代码的相关资料,学习java 基础的朋友可以参考下这个简单示例,需要的朋友可以参考下
具体要求如下:使用JTabbedPane,建立三个选项卡“成绩输入”、“成绩查询”、“成绩排序” ① 成绩输入:从界面上输入学生的学号和成绩,点击“确认”按钮进行保存。 ② 成绩查询:输入学生的学号,点击“查询”...
我们正在使用一个小技巧来缩进自定义 JTabbedPane 中的选项卡组件。 它在我们的测试中运行良好,但我们需要更多的测试。 请参阅下面的贡献部分。 Metal LAF 有一个已知的小问题。 此 LAF 中的标签有一个与下一个...
JTabbedPanel的美化标签很详细,找了很久
该源码由源码天堂免费提供下载,源码实现怎样自定义选项卡的背景颜色和图片,设置透明的选项卡,以及动态改变标签上的图片和动态增加删除tab。最后,还可以隐藏选项卡。是一个不错的学习例子,喜欢的朋友可以下载...
动态删减选项卡的效果示例! 值得下载看看!资源免费,大家分享!! 更多免费资源 http://ynsky.download.csdn.net/
主要介绍了Java Swing中的下拉式菜单(menu)、弹出式菜单(JPopupMenu)、选项卡窗体(JTabbedPane)组件使用案例,需要的朋友可以参考下