首页 > 编程语言 >JavaSwing JCombox

JavaSwing JCombox

时间:2024-12-07 19:42:58浏览次数:6  
标签:jFrame JCombox 窗体 设置 new JavaSwing data select

try
        {
            BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;
            //UIManager.put("RootPane.setupButtonVisible", false);
            org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
            
        }
        catch(Exception e)
        {
            //TODO exception
        }
        
        // 创建窗体对象
        JFrame jFrame =new JFrame();
        // 设置窗体大小
        jFrame.setSize(800, 500);
        // 设置窗体全屏展示
        //jFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
        // 设置窗体显示位置
        //jFrame.setLocation(100,200);
        // 设置窗体显示正中间
        jFrame.setLocationRelativeTo(null);
        // 设置窗体标题
        jFrame.setTitle("窗体标题");
        // 设置窗体不可全屏显示
        //jFrame.setResizable(false);
        // 设置窗体关闭后退出程序
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //设置此窗口是否应该始终位于其他窗口上方
        jFrame.setAlwaysOnTop(true);
        // 设置窗体图标
        jFrame.setIconImage(new ImageIcon(HelloWorld.class.getResource("/images/book.png")).getImage());
        

        
        // 创建容器
        JPanel jPanel =new JPanel(null);

        JComboBox<String> select =new JComboBox<String>(); 
        DefaultComboBoxModel<String> data= new DefaultComboBoxModel<String>();
        data.addElement("BJ");
        data.addElement("SH");
        data.addElement("WH");
        select.setModel(data);
        select.setSize(300, 30);
        select.setLocation(10, 10);
        
        // 设置下拉选可编辑
        select.setEditable(true);
        
        // 获取被选中的下拉选选项
        String item=(String) select.getSelectedItem();
        
        // 给选拉选添加监听器
        select.addItemListener(new ItemListener() {
            
            @Override
            public void itemStateChanged(ItemEvent e) {
                // 由于item的选中和未选中都会执行一次,所有要进行判断,只选中的才进行触发
                if(e.getStateChange()==ItemEvent.SELECTED) {
                    System.out.println("-----");
                }
                
                
            }
        });
        
        
        jPanel.add(select);
        jFrame.setContentPane(jPanel);

        
        // 设置窗体可见
        jFrame.setVisible(true);

 

标签:jFrame,JCombox,窗体,设置,new,JavaSwing,data,select
From: https://www.cnblogs.com/liangqingyun/p/18592586

相关文章

  • JavaSwing JList
    try{BeautyEyeLNFHelper.frameBorderStyle=BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;//UIManager.put("RootPane.setupButtonVisible",false);org.jb2011.lnf.beautyeye.BeautyEyeLNFHelpe......
  • JavaSwing JSlider
    try{BeautyEyeLNFHelper.frameBorderStyle=BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;//UIManager.put("RootPane.setupButtonVisible",false);org.jb2011.lnf.beautyeye.BeautyEyeLNFHelpe......
  • JavaSwing JProcessBar
    try{BeautyEyeLNFHelper.frameBorderStyle=BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;//UIManager.put("RootPane.setupButtonVisible",false);org.jb2011.lnf.beautyeye.BeautyEyeLNFHelpe......
  • JavaSwing JRadioButton
    try{BeautyEyeLNFHelper.frameBorderStyle=BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;//UIManager.put("RootPane.setupButtonVisible",false);org.jb2011.lnf.beautyeye.BeautyEyeLNFHelpe......
  • JavaSwing JCheckBox
    try{BeautyEyeLNFHelper.frameBorderStyle=BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;//UIManager.put("RootPane.setupButtonVisible",false);org.jb2011.lnf.beautyeye.BeautyEyeLNFHelpe......
  • JavaSwing JTextArea
    try{BeautyEyeLNFHelper.frameBorderStyle=BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;//UIManager.put("RootPane.setupButtonVisible",false);org.jb2011.lnf.beautyeye.BeautyEyeLNFHelpe......
  • JavaSwing JTextField
    try{BeautyEyeLNFHelper.frameBorderStyle=BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;//UIManager.put("RootPane.setupButtonVisible",false);org.jb2011.lnf.beautyeye.BeautyEyeLNFHelpe......
  • JavaSwing JLabel
    JLabellabel=newJLabel();//设置标签文本label.setText("标签组件");//设置文本水平居中label.setHorizontalTextPosition(SwingConstants.CENTER);//设置文本上下居中label.setVerticalTextPosition(SwingConstants......
  • JavaSwing JButton
    JButtonbtn01=newJButton("btn01");//设置按钮图标//btn01.setIcon(newImageIcon(HelloWorld.class.getResource("/images/book.png")));//设置按钮被按下后图标//btn01.setPressedIcon(newImageIcon(HelloWorld.class.getRes......
  • JavaSwing 事件处理
    1.事件类型 2.ActionListener  a:如果同一个组件添加了多个监听器,则每个监听器都会被执行, 后添加监听器会先被执行!  b: 同一个监听器对象,可以监听多个组件!  try{BeautyEyeLNFHelper.frameBorderStyle=BeautyEyeLNFHelper.FrameBo......