Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Panel Slider for java swing

import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class JCollapsiblePanel extends JPanel {
  private TitledBorder border;
  private Dimension visibleSize;
  private boolean collapsible;

  public JCollapsiblePanel(String title, Color titleCol) {
    super();

    collapsible = true;

    border = new TitledBorder(title);
    border.setTitleColor(titleCol);
    border.setBorder(new LineBorder(Color.white));
    setBorder(border);

    // as Titleborder has no access to the Label we fake the size data ;)
    final JLabel l = new JLabel(title);
    Dimension size = l.getPreferredSize();

    addMouseListener(new MouseAdapter() {
      @Override
      public void mouseClicked(MouseEvent e) {
        if (!collapsible) {
          return;
        }

        Insets i = getBorder().getBorderInsets(JCollapsiblePanel.this);
        if (e.getX() < i.left + size.width && e.getY() < i.bottom + size.height) {
          if (visibleSize == null || getHeight() > size.height) {
            visibleSize = getSize();
          }
          if (getSize().height < visibleSize.height) {
            setMaximumSize(new Dimension(visibleSize.width, 20000));
            setMinimumSize(visibleSize);
          } else {
            setMaximumSize(new Dimension(visibleSize.width, size.height));
          }
          revalidate();
          e.consume();
        }
      }
    });
  }

  public void setCollapsible(boolean collapsible) {
    this.collapsible = collapsible;
  }

  public void setTitle(String title) {
    border.setTitle(title);
  }
}
Comment

PREVIOUS NEXT
Code Example
Java :: remoce last character froma java string 
Java :: open a new activity on click of a button 
Java :: programatically close a jframe 
Java :: how to build a java main menu 
Java :: spring data rest format date 
Java :: How to find the Levenshtein distance between two strings of characters, in Java? 
Java :: java verify string is hexadecimal 
Java :: create file android java specific folder 
Java :: clear back stack android 
Java :: map java get first key 
Java :: android highlight part of textview 
Java :: collect as arr java 8 
Java :: get block player is looking at bukkit 
Java :: how to set landscape in android studio 
Java :: close scanner java 
Java :: check the string has spaces in it in java 
Java :: inputing number in java 
Java :: android studio get string 
Java :: java shorthand if 
Java :: print a to z in java 
Java :: How to compare lists of custom classes without defining equals() and hashCode()? 
Java :: java program to find perimeter of rectangle 
Java :: java array loop backwards 
Java :: char cannot be converted to string 
Java :: java equals ignore case 
Java :: char equals java 
Java :: java hello world 
Java :: java print two dimensional array 
Java :: {} when initialising arraylist java 
Java :: char array to string java 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =