Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.Color;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.plaf.basic.BasicComboBoxUI;

public final class Main {
    public static void main(String[] args) {
        String[] items = { "A", "B", "C" };
        JComboBox<String> comboBox1 = new MyComboBox1<>(items);
        JPanel p = new JPanel();
        p.add(comboBox1);

        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(p);
        f.setSize(320, 240);
        f.setVisible(true);
    }
}

class MyComboBox1<E> extends JComboBox<E> {
    public MyComboBox1(E[] list) {
        super(list);
    }

    @Override
    public void updateUI() {
        super.updateUI();
        setUI(new BasicComboBoxUI() {
            @Override
            protected JButton createArrowButton() {
                return new JButton() {
                    @Override
                    public int getWidth() {
                        return 0;
                    }
                };
            }
        });
        setBorder(BorderFactory.createLineBorder(Color.GRAY));
    }
}