- 浏览: 726098 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
lingsuch:
Android网络连接判断与处理 -
月光照着我:
写的不错,作为笔记了
Android中LayoutInflater的使用 -
智博王锋:
好文章是要顶的!
Android中LayoutInflater的使用 -
云南白药:
...
Android中LayoutInflater的使用 -
万新one:
理解了许多。解释的不错。3Q.
Android中LayoutInflater的使用
import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.awt.Cursor; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Insets; import java.awt.LayoutManager; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JSplitPane; import javax.swing.UIManager; import javax.swing.border.Border; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicSplitPaneDivider; import javax.swing.plaf.basic.BasicSplitPaneUI; import sun.swing.DefaultLookup; public class MySplitPaneUI extends BasicSplitPaneUI { private static final Color BG_COLOR = Color.BLACK; public JButton theL$UButton, theR$DButton; public MySplitPaneUI() { super(); } public static ComponentUI createUI(JComponent c) { return new MySplitPaneUI(); } @Override public void paint(Graphics g, JComponent c) { super.paint(g, c); g.setColor(Color.BLACK); int width = c.getWidth(); int height = c.getHeight(); g.drawRect(3, 3, width - 6, height - 6); } /** * Creates the default divider. */ @Override public BasicSplitPaneDivider createDefaultDivider() { return new MyBasicSplitPaneDivider(this); } private class MyBasicSplitPaneDivider extends BasicSplitPaneDivider { private static final long serialVersionUID = 1L; private int oneTouchSize, oneTouchOffset; boolean centerOneTouchButtons; /* Center空白区域 */ private int area_x, area_y; @SuppressWarnings("unchecked") public MyBasicSplitPaneDivider(MySplitPaneUI ui) { super(ui); oneTouchSize = DefaultLookup.getInt(ui.getSplitPane(), ui, "SplitPane.oneTouchButtonSize", ONE_TOUCH_SIZE); oneTouchOffset = DefaultLookup.getInt(ui.getSplitPane(), ui, "SplitPane.oneTouchButtonOffset", ONE_TOUCH_OFFSET); centerOneTouchButtons = DefaultLookup.getBoolean(ui.getSplitPane(), ui, "SplitPane.centerOneTouchButtons", true); //oneTouchSize = ONE_TOUCH_SIZE; //oneTouchOffset = ONE_TOUCH_OFFSET; //centerOneTouchButtons = true; setLayout(new DividerLayout()); setBasicSplitPaneUI(ui); orientation = splitPane.getOrientation(); setCursor((orientation == JSplitPane.HORIZONTAL_SPLIT) ? Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR) : Cursor .getPredefinedCursor(Cursor.S_RESIZE_CURSOR)); setBackground(UIManager.getColor("SplitPane.background")); } /** * Creates and return an instance of JButton that can be used to collapse the right component in the split pane. */ @SuppressWarnings("serial") @Override protected JButton createRightOneTouchButton() { JButton b = new JButton() { public void setBorder(Border border) { } @Override public void paint(Graphics g) { if (splitPane != null) { int[] xs = new int[3]; int[] ys = new int[3]; int blockSize; // Fill the background first ... g.setColor(Color.WHITE); g.fillRect(0, 0, this.getWidth(), this.getHeight()); // ... then draw the arrow. if (orientation == JSplitPane.VERTICAL_SPLIT) { blockSize = Math.min(getHeight(), oneTouchSize); xs[0] = blockSize; xs[1] = blockSize << 1; xs[2] = 0; ys[0] = blockSize; ys[1] = ys[2] = 0; } else { blockSize = Math.min(getWidth(), oneTouchSize); xs[0] = xs[2] = 0; xs[1] = blockSize; ys[0] = 0; ys[1] = blockSize; ys[2] = blockSize << 1; } g.setColor(BG_COLOR); g.fillPolygon(xs, ys, 3); } } // Don't want the button to participate in focus traversable. public boolean isFocusTraversable() { return false; } }; b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize)); b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); b.setFocusPainted(false); b.setBorderPainted(false); b.setRequestFocusEnabled(false); return b; } /** * Creates and return an instance of JButton that can be used to collapse the left component in the split pane. */ protected JButton createLeftOneTouchButton() { @SuppressWarnings("serial") JButton b = new JButton() { public void setBorder(Border b) { } public void paint(Graphics g) { if (splitPane != null) { int[] xs = new int[3]; int[] ys = new int[3]; int blockSize; // Fill the background first ... g.setColor(Color.WHITE); g.fillRect(0, 0, this.getWidth(), this.getHeight()); // ... then draw the arrow. g.setColor(BG_COLOR); if (orientation == JSplitPane.VERTICAL_SPLIT) { blockSize = Math.min(getHeight(), oneTouchSize); xs[0] = blockSize; xs[1] = 0; xs[2] = blockSize << 1; ys[0] = 0; ys[1] = ys[2] = blockSize; g.drawPolygon(xs, ys, 3); // Little trick to make the // arrows of equal size } else { blockSize = Math.min(getWidth(), oneTouchSize); xs[0] = xs[2] = blockSize; xs[1] = 0; ys[0] = 0; ys[1] = blockSize; ys[2] = blockSize << 1; } g.fillPolygon(xs, ys, 3); } } // Don't want the button to participate in focus traversable. public boolean isFocusTraversable() { return false; } }; b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize)); b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); b.setFocusPainted(false); b.setBorderPainted(false); b.setRequestFocusEnabled(false); return b; } @Override public void paint(Graphics g) { super.paint(g); Dimension size = getSize(); g.setColor(BG_COLOR); g.fillRect(1, 1, size.width - 1, size.height - 1); g.setColor(Color.GRAY); g.drawRect(0, 0, size.width, size.height); g.setColor(Color.WHITE); //分为水平时跟垂直时,白色区域 if (orientation == JSplitPane.VERTICAL_SPLIT) { g.fillRect(area_x, 1, 30, size.height - 1); } else { g.fillRect(1, area_y, size.width - 1, 30); } theL$UButton = leftButton; theR$DButton = rightButton; if (leftButton != null) { leftButton.repaint(); } if (rightButton != null) { rightButton.repaint(); } } /** * Used to layout a <code>BasicSplitPaneDivider</code>. Layout for the divider involves appropriately moving the left/right buttons around. * <p> */ protected class DividerLayout implements LayoutManager { public void layoutContainer(Container c) { if (leftButton != null && rightButton != null) { if (splitPane.isOneTouchExpandable()) { Insets insets = getInsets(); if (orientation == JSplitPane.VERTICAL_SPLIT) { int extraX = (insets != null) ? insets.left : 0; int blockSize = getHeight(); if (insets != null) { blockSize -= (insets.top + insets.bottom); blockSize = Math.max(blockSize, 0); } blockSize = Math.min(blockSize, oneTouchSize); int y = (c.getSize().height - blockSize) / 2; if (!centerOneTouchButtons) { y = (insets != null) ? insets.top : 0; extraX = 0; } int width = (int) MyBasicSplitPaneDivider.this.getSize().getWidth(); area_x = width / 2 - oneTouchSize; leftButton.setBounds(extraX - oneTouchOffset + width / 2, y, blockSize * 2, blockSize); rightButton.setBounds(extraX - oneTouchOffset + oneTouchSize * 2 + width / 2, y, blockSize * 2, blockSize); } else { int extraY = (insets != null) ? insets.top : 0; int blockSize = getWidth(); if (insets != null) { blockSize -= (insets.left + insets.right); blockSize = Math.max(blockSize, 0); } blockSize = Math.min(blockSize, oneTouchSize); int x = (c.getSize().width - blockSize) / 2; if (!centerOneTouchButtons) { x = (insets != null) ? insets.left : 0; extraY = 0; } int height = (int) MyBasicSplitPaneDivider.this.getSize().getHeight(); area_y = height / 2 - oneTouchSize; leftButton.setBounds(x, extraY - oneTouchOffset + height / 2, blockSize, blockSize * 2); rightButton.setBounds(x, extraY - oneTouchOffset + oneTouchSize * 2 + height / 2, blockSize, blockSize * 2); } } else { leftButton.setBounds(-5, -5, 1, 1); rightButton.setBounds(-5, -5, 1, 1); } } } public Dimension minimumLayoutSize(Container c) { // NOTE: This isn't really used, refer to // BasicSplitPaneDivider.getPreferredSize for the reason. // I leave it in hopes of having this used at some point. if (splitPane == null) { return new Dimension(0, 0); } Dimension buttonMinSize = null; if (splitPane.isOneTouchExpandable() && leftButton != null) { buttonMinSize = leftButton.getMinimumSize(); } Insets insets = getInsets(); int width = getDividerSize(); int height = width; if (orientation == JSplitPane.VERTICAL_SPLIT) { if (buttonMinSize != null) { int size = buttonMinSize.height; if (insets != null) { size += insets.top + insets.bottom; } height = Math.max(height, size); } width = 1; } else { if (buttonMinSize != null) { int size = buttonMinSize.width; if (insets != null) { size += insets.left + insets.right; } width = Math.max(width, size); } height = 1; } return new Dimension(width, height); } public Dimension preferredLayoutSize(Container c) { return minimumLayoutSize(c); } public void removeLayoutComponent(Component c) { } public void addLayoutComponent(String string, Component c) { } } // End of class BasicSplitPaneDivider.DividerLayout } }
发表评论
-
Swing中引入Android的NinePatch技术,让Swing拥有Android的外观定制能力
2012-09-21 09:22 1595【摘要】 本文诣在 ... -
JavaSwing实现支持合并拆分的JTable
2010-12-16 15:39 1948GridBagModel:抽象模型接口。该接口用于描述表格中单 ... -
JTable小例子,表格中使用JComboBox下拉按钮
2010-12-16 15:21 5402import java.awt.BorderLayout; ... -
配合滚动面板实现JTable上下翻页的效果
2010-12-16 14:26 3387import java.awt.BorderLayout; ... -
JScrollBar简单演示例子
2010-12-06 19:28 6588import java.awt.*; import java ... -
点击jtable的表头,数据会根据根据表头来排序
2010-12-06 11:47 5095import javax.swing.JFrame; imp ... -
Swing窗口初始最大化的方法
2010-08-20 11:09 78571.设置窗口最大(伪最大化) JFrame frame =n ... -
Tree目录实现拖拽功能演示实例(DragAndDrop)
2010-08-10 16:49 1771import java.awt.BorderLayout; ... -
设置JTextPane指定内容的颜色
2010-05-21 14:29 1331package Assis; import java.a ... -
ScaleImageDemo图像缩小与放大演示
2010-05-12 14:59 2079package Assis; import java.a ... -
TreesDemo
2010-05-04 11:19 1055import java.awt.*; import java ... -
TableDemo
2010-05-04 11:17 1170import javax.swing.JTable; imp ... -
分割面板演示JSplitPaneDemo
2010-05-04 11:12 1361//Java Swing 带分隔条的面板代码 impor ... -
StylesExample8
2010-04-08 12:55 1173import javax.swing.*; import j ... -
StylesExample7
2010-04-08 12:54 971import javax.swing.*; import j ... -
StylesExample6
2010-04-08 12:52 1040import javax.swing.*; import j ... -
StylesExample5
2010-04-08 12:51 975import javax.swing.*; import j ... -
StylesExample4
2010-04-08 12:50 1079import javax.swing.*; import j ... -
StylesExample3
2010-04-08 12:50 975import javax.swing.*; import j ... -
StylesExample2
2010-04-08 12:49 1028import javax.swing.*; import j ...
相关推荐
JSplitPane
JSplitPane的具体用法,分隔面板的使用,适合初学者。若是有更深层的见解,请作补充
JSplitPane是Swing库提供的一个分割面板组件。它可以在图形界面中创建两个子组件,并允许用户通过拖动分割条来调整子组件的大小。
NULL 博文链接:https://silentwu.iteye.com/blog/1605617
这是一个成绩管理系统,对于初学者来说,值得拿来看看。
主要介绍了Java Swing中的工具栏(JToolBar)和分割面版(JSplitPane)组件使用案例,本文直接给出代码实例和效果截图,需要的朋友可以参考下
主要为大家详细介绍了Swing拆分窗格控件JSplitPane的使用方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
主要为大家详细介绍了swing分割窗口控件JSplitPane的使用方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
XML的树形目录,转载。
JSplitPane spane=new JSplitPane(JSplitPane.VERTICAL_SPLIT); //实例化分隔面板 p1.add(new JLabel("地址")); //增加组件到面板上 p1.add(jtfAddress); spane.add(new JScrollPane(jtpShow),...
本章目标;常见的GUI组件;Swing vs AWT;GUI API;Container(容器);Component(组件类);Helper(辅助类);GUI开发的层次结构 ;...分割条面板JSplitPane;分割条面板JSplitPane;;菜单;使用菜单;Color类;Font类;ImageIcon类
JSplitPane split=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); //实例化分隔面板 split.setDividerLocation(140); //设置分隔位置 split.add(list); //增加组件到分隔面板 split.add(jta); ...
JAVA JTREE实例代码、JAVA JTABLE实例代码
1.JPanel面板 2.JScrollPane滚动窗格 3.JSplitPane拆分窗格
2 主窗体的显示,JFRAME 类实现,JSplitPane.HORIZONTAL_SPLIT类将主窗体左右分割 3 JPanel 应用 创建 LEFT 1 2 3,RIGHT 1 2 3来添加左右窗体 4 获取当前日期Calendar类实现 Calendar.Year Calendar.Month ...
MapEagleEyesPanel工程中定义了地图...MainFrame通过JSplitPane容器分别添加主地图控件,鹰眼面板和放大镜面板。主地图刷新时更新鹰眼面板和放大镜面板的地图,鹰眼面板的红框改变位置也同步更新主地图和放大镜面板。
如何使用面板组件 使用JPanel 使用JScrollPane 使用JSplitPane 使用JTabbedPane 使用JIntemalFrame 使用JLayeredPane 使用JRootPane
容器:JTabbedPane/JScrollPane/JSplitPane/JInternalFrame 组件:JTable/JTree/JList 基本组件:ToggleButtons/JButton/JComboBox/ProgressBar/Slider/Spinner/TextFeild/JEditorPane 选择器:JColorChooser/...
句法: [h1,h2,hDivider] = uisplitpane(hParent,'propName',propVal,...) 描述: UIPLITPANE 将指定的容器(图形、面板或框架,由句柄 hParent 引用)拆分为由可移动分隔线分隔的两个不同的窗格(面板)。...
一个JSplitPane,左边JTree,右边JTable。实现学生管理系统 连接数据库获取数据表