Class SwingTools

java.lang.Object
eu.bandm.tools.graficUtils.SwingTools

public class SwingTools extends Object
Collection of small static utility functions.
  • Method Details

    • setMaximumToPreferred

      public static void setMaximumToPreferred(Component c)
    • nearestContainer

      @Opt public static <C extends Container> C nearestContainer(@Opt @Opt Component c, Class<C> cl)
    • show

      public static <D extends Message> void show(JFrame frame, @Opt @Opt String windowtitle, int messageType, MessageStore<D> text, String buttonText)
    • show

      public static void show(JFrame frame, @Opt @Opt String windowtitle, int messageType, Object[] text, String buttonText)
      ATTENTION: when calling "showXXDialog()", the conversion to "Object[]" must be done explicitly, because only then "vertical stacking" is applied to the results of "toString()" separately!
    • ask

      public static <D extends Message> boolean ask(JFrame frame, @Opt @Opt String windowtitle, int messageType, MessageStore<D> text, String cancelbutton, String okbutton)
    • ask

      public static boolean ask(JFrame frame, @Opt @Opt String windowtitle, int messageType, Object[] text, String cancelbutton, String okbutton)
    • appendFileToTextArea

      public static int appendFileToTextArea(File file, JTextArea ta) throws IOException
      Throws:
      IOException
    • loadPngsToButtons

      public static int loadPngsToButtons(JPanel container, File directory, String fileStem, int numStart, String numberFormat)
      Load one or more ".png" files to JButtons and append them to the end of the container. In case of lilypond use "-page%d" as the numberFormat.
      Returns:
      -1 if ONE page without numeric extension has been loaded; otherwise the first number which could NOT be loaded (e.g. "3" if pages "1" and "2" have been successfully loaded)
    • setEnabling

      public static <E> JComboBox<E> setEnabling(JComboBox<E> comboBox)
      Adds disabling/enabling to the items of a JComboBox. Changes the data model, so it must be called before filling this.
    • setEnabling

      public static <E> JComboBox<E> setEnabling(JComboBox<E> comboBox, @Opt @Opt Predicate<E> enabled)
    • setPredicate

      public static <E> JComboBox<E> setPredicate(JComboBox<E> comboBox, @Opt @Opt Predicate<E> enabled)
      Changes the predicate for a JComboBox with disabling/enabling. Assumes that setEnabling(JComboBox,Predicate) has been called before. Or some other means have changed the renderer and the data model to a class which has "setPredicate()".
      Parameters:
      enabled - the enabling predicate, or null for all items enabled.
      Throws:
      ClassCastException - if setEnabling(JComboBox,Predicate) has not been called before.
    • itemSelectedListener

      public static ItemListener itemSelectedListener(Consumer<Object> consumer)
      Create a listener which only reacts on set events, not on clear evants. An ItemEvent is more selective than an Action event, e.g. with JComboBox, because it is not fired if nothing changes. But when the selection changes, two events are fired, for the de-selected and the selected value. This class propages only the latter.