Terai Atsuhiro 2024-11-19 (火) 15:25:21

http://terai.xrea.jp/swing/accordionpanel/screenshot.png

public ExpansionPanel(String title_) {
  title = title_;

    protected void paintComponent(Graphics g) {
      Graphics2D g2 = (Graphics2D)g;
      Insets ins = getInsets();
      g2.setPaint(new GradientPaint(50, 0, Color.white,
                  getWidth(), getHeight(), new Color(200,200,255)));
      g2.fillRect(0, 0, getWidth(), getHeight());
      super.paintComponent(g);
    }
  };
  label.addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent evt) {
      openFlag = !openFlag;
      initPanel();
      fireExpansionEvent();
    }
  });
  label.setForeground(Color.blue);
  label.setBorder(BorderFactory.createEmptyBorder(2,5,2,2));
  panel = makePanel();
  panel.setOpaque(true);
  Border outBorder = BorderFactory.createMatteBorder(0,2,2,2,Color.white);
  Border inBorder  = BorderFactory.createEmptyBorder(10,10,10,10);
  Border border    = BorderFactory.createCompoundBorder(outBorder, inBorder);
  panel.setBorder(border);
  panel.setBackground(new Color(240, 240, 255));
  setLayout(new BorderLayout());
  add(label, BorderLayout.NORTH);
}