swing其他高级面板
2017-04-22 17:45
162 查看
分割面板的简单使用
UI小部件的所用是用鼠标拖拽分割条时,面板则重绘(标签内容的位置在随时发生改变)
选项卡面板的简单使用
桌面面板
import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JSplitPane; public class ExampleFrame extends JFrame { /** * */ private static final long serialVersionUID = 1L; public static void main(String[] args) { ExampleFrame frame=new ExampleFrame(); frame.setVisible(true); } public ExampleFrame() { super(); setTitle("分割面板"); setBounds(100,100,500,375); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JSplitPane splitPane=new JSplitPane(); splitPane.setDividerLocation(40); //分割条左侧宽度为40 getContentPane().add(splitPane, BorderLayout.CENTER); splitPane.setLeftComponent(new JLabel(" 1")); final JSplitPane vsplitPane=new JSplitPane(JSplitPane.VERTICAL_SPLIT); vsplitPane.setDividerLocation(30); vsplitPane.setDividerSize(8); //设置分割条的宽度为8 vsplitPane.setOneTouchExpandable(true); //使用ui小部件 vsplitPane.setContinuousLayout(true); //调整分割条的位置时面板的的重绘方式为连续绘制 splitPane.setRightComponent(vsplitPane); vsplitPane.setLeftComponent(new JLabel(" 2")); vsplitPane.setRightComponent(new JLabel(" 3")); } }
UI小部件的所用是用鼠标拖拽分割条时,面板则重绘(标签内容的位置在随时发生改变)
选项卡面板的简单使用
import java.awt.BorderLayout; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTabbedPane; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public class TabbedPane extends JFrame { /** * */ private static final long serialVersionUID = 1L; public static void main(String[] args) { TabbedPane frame=new TabbedPane(); frame.setVisible(true); } TabbedPane() { super("选项卡面板"); setSize(300,300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTabbedPane tabbedPane=new JTabbedPane(); tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);//滚动布局 tabbedPane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) //选项动作响应 { int selectedIndex=tabbedPane.getSelectedIndex(); String title=tabbedPane.getTitleAt(selectedIndex); System.out.println(title); } }); getContentPane().add(tabbedPane, BorderLayout.CENTER); ImageIcon imageIcon=new ImageIcon("G:\\sourse\\timg(1).jpg");//设置磁盘文件为图标 ImageIcon imageIcon1=new ImageIcon("G:\\sourse\\5(1).jpg"); final JLabel la=new JLabel(); la.setText("选项卡A"); tabbedPane.addTab("选项卡A",imageIcon,la,"点击查看选项卡A"); final JLabel la1=new JLabel(); la1.setText("选项卡B"); tabbedPane.addTab("选项卡B",imageIcon1,la1,"点击查看选项卡B"); final JLabel la2=new JLabel("选项卡C"); tabbedPane.addTab("选项卡C",imageIcon1,la2,"点击查看选项卡C"); tabbedPane.setSelectedIndex(1); //设置索引为1的选项卡被选中 tabbedPane.setEnabledAt(0,false); //索引为0的选项卡不可用 }
}
桌面面板
import java.awt.BorderLayout;桌面面板和内部窗体
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class JDeskPane extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
public static void main(String [] args)
{
JDeskPane jd=new JDeskPane();
jd.pane();
jd.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jd.setVisible(true);
}public JDeskPane()
{
super("JDesktopPane面板");
}private void pane()
{
final JDesktopPane desktopPane=new JDesktopPane();
setSize(369,300);
getContentPane().add(desktopPane,BorderLayout.CENTER);
final JLabel backLabel=new JLabel();
ImageIcon icon=new ImageIcon("G:\\sourse\\flawer.jpg");
backLabel.setIcon(icon);
backLabel.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight());
desktopPane.add(backLabel,new Integer(Integer.MIN_VALUE));
}}
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Interframe extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 6036055622976411906L;
JDesktopPane desktopPane=null;
JInternalFrame pInternalFrame=null;
JInternalFrame hInternalFrame=null;
JInternalFrame iInternalFrame=null;
JInternalFrame aInternalFrame=null;
public static void main(String[] args)
{
Interframe frame=new Interframe();
frame.setVisible(true);
}public Interframe()
{
super();
setTitle("班级管理系统");
setBounds(100,100,369,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
desktopPane=new JDesktopPane(); //创建桌面面板对象
desktopPane.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
getContentPane().add(desktopPane, BorderLayout.CENTER);
final JLabel backLabel=new JLabel();
ImageIcon icon=new ImageIcon("G:\\sourse\\flawer.jpg"); //设置背景图片
backLabel.setIcon(icon);
backLabel.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight());
//将背景放在最底层
desktopPane.add(backLabel,new Integer(Integer.MIN_VALUE));
JButton jb=new JButton("零班");
JButton jb1=new JButton("一班");
JButton jb2=new JButton("二班");
JButton jb3=new JButton("三班");
JPanel jp=new JPanel();
getContentPane().add(jp,BorderLayout.NORTH);
jp.add(jb);
jp.add(jb1);
jp.add(jb2);
jp.add(jb3);
jb.addActionListener(new aInternalFrameActionListener());
jb1.addActionListener(new pInternalFrameActionListener());
jb2.addActionListener(new hInternalFrameActionListener());
jb3.addActionListener(new iInternalFrameActionListener());
}private class aInternalFrameActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e) {
if(aInternalFrame==null||aInternalFrame.isClosed())
{
JInternalFrame[] allFrames=desktopPane.getAllFrames();
int titleBarHight=30*allFrames.length;
int x=10+titleBarHight, //设置窗口的显示位置
y=x;
int width=369,height=300; //设置窗体的大小
aInternalFrame=new JInternalFrame("零班",true,true,true,true); //创建窗体及设置其参数
aInternalFrame.setBounds(x,y,width,height);
aInternalFrame.setVisible(true);
desktopPane.add(aInternalFrame);
}try
{
aInternalFrame.setSelected(true); //选中床体
}catch(PropertyVetoException propertyVetoE)
{
propertyVetoE.printStackTrace();
}ImageIcon icon=new ImageIcon("G:\\sourse\\5(1).jpg");
aInternalFrame.setFrameIcon(icon);
}}private class pInternalFrameActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e) {
if(pInternalFrame==null||pInternalFrame.isClosed())
{
JInternalFrame[] allFrames=desktopPane.getAllFrames();
int titleBarHight=30*allFrames.length;
int x=10+titleBarHight,
y=x;
int width=369,height=300;
pInternalFrame=new JInternalFrame("一班",true,true,true,true);
pInternalFrame.setBounds(x,y,width,height);
pInternalFrame.setVisible(true);
desktopPane.add(pInternalFrame);
}try
{
pInternalFrame.setSelected(true);
}catch(PropertyVetoException propertyVetoE)
{
propertyVetoE.printStackTrace();
}ImageIcon icon=new ImageIcon("G:\\sourse\\5(1).jpg");
pInternalFrame.setFrameIcon(icon);
}}private class hInternalFrameActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e) {
if(hInternalFrame==null||hInternalFrame.isClosed())
{
JInternalFrame[] allFrames=desktopPane.getAllFrames();
int titleBarHight=30*allFrames.length;
int x=10+titleBarHight,
y=x;
int width=369,height=300;
hInternalFrame=new JInternalFrame("二班",true,true,true,true);
hInternalFrame.setBounds(x,y,width,height);
hInternalFrame.setVisible(true);
desktopPane.add(hInternalFrame);
}try
{
hInternalFrame.setSelected(true);
}catch(PropertyVetoException propertyVetoE)
{
propertyVetoE.printStackTrace();
}ImageIcon icon=new ImageIcon("G:\\sourse\\5(1).jpg");
hInternalFrame.setFrameIcon(icon);
}}private class iInternalFrameActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e) {
if(iInternalFrame==null||iInternalFrame.isClosed())
{
JInternalFrame[] allFrames=desktopPane.getAllFrames();
int titleBarHight=30*allFrames.length;
int x=10+titleBarHight,
y=x;
int width=369,height=300;
iInternalFrame=new JInternalFrame("三班",true,true,true,true);
iInternalFrame.setBounds(x,y,width,height);
iInternalFrame.setVisible(true);
desktopPane.add(iInternalFrame);
}try
{
iInternalFrame.setSelected(true);
}catch(PropertyVetoException propertyVetoE)
{
propertyVetoE.printStackTrace();
}ImageIcon icon=new ImageIcon("G:\\sourse\\5(1).jpg");
iInternalFrame.setFrameIcon(icon);
}}}
相关文章推荐
- 【教程】将面板和其他Swing组件绘制到PDF文档
- 【教程】将面板和其他Swing组件绘制到PDF文档
- Swing高级控件
- 基于Bootstrap 3.x的免费高级管理控制面板主题:AdminLTE
- Java核心技术(高级Swing)三文本构件
- swing设置面板背景图片
- ExtJs 关于Tabpanel与fieldset切换时 fieldset在其他tab面板无法显示
- Swing面板上调整JTable的行高和列宽,以及表格超出JScorllPane时设置滚动条
- JAVASE_21_#java高级IO_IO包中的其他类
- java高级图形界面编程-Swing中的对话框
- java.swing 容器与面板之间的关系以及正确使用方法
- Java swing创建按钮并添加到面板中
- 分层Pane结构与Swing组件高级特性的实现
- Win7"更改高级共享设置"网络发现不能启用,无法搜索和共享其他电脑的文件
- Axure学习之线框图-动态面板高级篇
- AXURE 7.0高级学习心得——中继器、热区、动态面板、全局变量、内联框架、模板、组合、团队合作等
- Java Swing 层次面板(JLayeredPanel) Demo
- swing入门教程(五) swing其他重要概念
- Java核心技术(高级Swing)一列表
- Swing 四种常见面板