package com.wolffy.ui; import javax.swing.BorderFactory; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.WindowConstants; import java.awt.BorderLayout; import java.awt.Color; /** * Created by Felix on 2019/05/30. */ public class Demo extends JFrame { private JPanel jPanel; private JComboBox jComboBox; public Demo() { initGUI(); } private void initGUI() { setSize(700, 500); //setUndecorated(true); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); jPanel = new JPanel(); jPanel.setLayout(null); jPanel.setBorder(BorderFactory.createLineBorder(Color.GRAY)); getContentPane().add(jPanel, BorderLayout.CENTER); String[] texts = {"张三", "李四", "王五", "赵六", "田七"}; jComboBox = new JComboBox<>(texts); //jComboBox.setEditable(true); jComboBox.setUI(new MyComboBoxUI()); jComboBox.setBounds(100, 70, 100, 50); jPanel.add(jComboBox); } public static void main(String[] args) { Demo demo = new Demo(); demo.setVisible(true); //demo.pack(); } }