专栏首页python3JTabbedPane(3)

JTabbedPane(3)

/* * TabbedPaneDemo.java requires one additional file: *   p_w_picpaths/middle.gif. */ import javax.swing.JTabbedPane; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JFrame; import javax.swing.JComponent; import javax.swing.SwingUtilities; import javax.swing.UIManager; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.KeyEvent; import javax.swing.JButton; public class TabbedPaneDemo extends JPanel {     public TabbedPaneDemo() {         super(new GridLayout(1, 1)); //        super(); JTabbedPane tabbedPane = new JTabbedPane();         ImageIcon icon = createImageIcon("p_w_picpaths/middle.gif");         JComponent panel1 = makeTextPanel("Panel #1","标签1");//增加一个选项卡         tabbedPane.addTab("Tab 1", icon, panel1,                 "Does nothing");         tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);         JComponent panel2 = makeTextPanel("Panel #2","标签2");         tabbedPane.addTab("Tab 2", icon, panel2,                 "Does twice as much nothing");         tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);         JComponent panel3 = makeTextPanel("Panel #3","标签3");         tabbedPane.addTab("Tab 3", icon, panel3,                 "Still does nothing");         tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);         JComponent panel4 = makeTextPanel(                 "Panel #4 (has a preferred size of 410 x 50).","标签4");         panel4.setPreferredSize(new Dimension(410, 50));         tabbedPane.addTab("Tab 4", icon, panel4,                 "Does nothing at all");         tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);         JComponent panel5 = makeTextPanel("Panel #5","标签5");         panel5.setPreferredSize(new Dimension(410,50));         tabbedPane.addTab("标签5", icon,panel5,"测试用标签");         //Add the tabbed pane to this panel.         add(tabbedPane);         //The following line enables to use scrolling tabs.         tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);     }     protected JComponent makeTextPanel(String text,String buttons) {//制定的组件         JPanel panel = new JPanel(false);         JLabel filler = new JLabel(text);         JButton button = new JButton(buttons);         filler.setHorizontalAlignment(JLabel.CENTER); //        panel.setLayout(new GridLayout(1, 1));         panel.add(filler);         panel.add(button);         return panel;     }     /** Returns an ImageIcon, or null if the path was invalid. */     protected static ImageIcon createImageIcon(String path) {         java.net.URL imgURL = TabbedPaneDemo.class.getResource(path);         if (imgURL != null) {             return new ImageIcon(imgURL);         } else {             System.err.println("Couldn't find file: " + path);             return null;         }     }     /**      * Create the GUI and show it. For thread safety,      * this method should be invoked from      * the event dispatch thread.      */     private static void createAndShowGUI() {         //Create and set up the window.         JFrame frame = new JFrame("TabbedPaneDemo");         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         //Add content to the window.         frame.add(new TabbedPaneDemo(), BorderLayout.CENTER);         //Display the window.         frame.pack();         frame.setVisible(true);     }     public static void main(String[] args) {         //Schedule a job for the event dispatch thread:         //creating and showing this application's GUI.         SwingUtilities.invokeLater(new Runnable() {             public void run() {                 //Turn off metal's use of bold fonts         UIManager.put("swing.boldMetal", Boolean.FALSE);         createAndShowGUI();             }         });     } }

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • 深度学习算法优化系列二 | 基于Pytorch的模型剪枝代码实战

    昨天讲了一篇ICLR 2017《Pruning Filters for Efficient ConvNets》 ,相信大家对模型剪枝有一定的了解了。今天我就剪一...

    BBuf
  • 0. 如何判断一门语言的好坏

    我在组内推广 Kotlin 遇到不少挑战,虽然我自己觉得它确实是一门优秀的语言,有着丰富的特性,能提高我们开发效率,减少 bug 的出现,但同事们并不觉得。而且...

    sickworm
  • 删除系统 Python 引发的惨案

    由于实验需要使用 Python3.6 以上版本,于是决定卸载 Python3.5。

    咸鱼学Python
  • .whl文件在python库的安装

    https://www.lfd.uci.edu/~gohlke/pythonlibs/

    微风、掠过
  • 厉害了!Python+matplotlib制作8个排序算法的动画

    深刻研究排序算法是入门算法较为好的一种方法,现在还记得4年前手动实现常见8种排序算法,通过随机生成一些数据,逐个校验代码实现的排序过程是否与预期的一致,越做越有...

    double
  • 生成Python函数一半没问题,当前最「正统」的代码生成是什么样的?

    开发者写代码,和数学家写公式一样是非常自然的一件事。开发者将完成某个任务的步骤和逻辑,一行行写成代码,并期待达到预定的效果。数学家从某个事实出发,将思考过程一行...

    机器之心
  • Kotlin 从拒绝到真香

    我在组内推广 Kotlin 遇到不少挑战,虽然我自己觉得它确实是一门优秀的语言,有着丰富的特性,能提高我们开发效率,减少 bug 的出现,但同事们并不觉得。而且...

    sickworm
  • robot framework笔记(二):在RF中自定义chrome启动参数

    在RF的登录中引用这个自定义的关键字,执行的时候如果提示找不到关键字GET CHROME OPTIONS,加一个环境变量PYTHONPATH, value就是p...

    free赖权华
  • ML学习笔记之Jupyter Notebook各种使用方法

    保存后在cmd中输入:jupyter notebook,会自动触发默认浏览器打开jupyter

    Jetpropelledsnake21
  • robot framework笔记(三):扩展SeleniumLibrary库 (自定义关键字)

    以下代码GitHub 版本库地址: https://github.com/blairwind/blog_rf

    free赖权华

扫码关注云+社区

领取腾讯云代金券