Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/parubok/multiline-label
Java Swing component to display multiline plain text.
https://github.com/parubok/multiline-label
java-11 java-module swing swing-component
Last synced: 4 months ago
JSON representation
Java Swing component to display multiline plain text.
- Host: GitHub
- URL: https://github.com/parubok/multiline-label
- Owner: parubok
- License: apache-2.0
- Created: 2020-08-04T17:42:49.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-08-24T14:33:35.000Z (5 months ago)
- Last Synced: 2024-09-28T23:20:59.416Z (4 months ago)
- Topics: java-11, java-module, swing, swing-component
- Language: Java
- Homepage:
- Size: 402 KB
- Stars: 13
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![Java CI with Maven](https://github.com/parubok/multiline-label/workflows/Java%20CI%20with%20Maven/badge.svg?branch=master)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/parubok/multiline-label/blob/master/LICENSE)
[![Latest Version](https://img.shields.io/maven-central/v/io.github.parubok/multiline-label)](https://search.maven.org/search?q=a:multiline-label)
[![javadoc](https://javadoc.io/badge2/io.github.parubok/multiline-label/javadoc.svg)](https://javadoc.io/doc/io.github.parubok/multiline-label)# multiline-label
Java Swing component to display a plain, left-to-right text (single line or multiline). Allows to specify preferred
wrapping width (in pixels) for cases when there is not enough room to display the text as a single line.Motivation: Though standard Swing provides a number of options to display multiline text (e.g. `JLabel` with HTML,
read-only `JTextArea`, etc.), none of them IMHO is very convenient and straightforward.
The goal of this component is to provide a multiline label with predictable and easily configurable behavior.The label allows to specify custom separator characters (a space character by default). See `MultilineLabel.setSeparators`.
The label always honors line breaks (e.g. `\n`) if they are present in the text.The label implements `javax.swing.Scrollable` interface to support scrolling. By default, up to 20 lines will be
displayed without vertical scroll bar. See `MultilineLabel.setPreferredViewportLineCount`.The `MultilineLabel` class provides a number of static methods to support multiline text painting on components other
than the `MultilineLabel`. For example, `MultilineLabel.calculatePreferredSize` method.Example:
```java
import javax.swing.border.EmptyBorder;
import java.util.Set;import io.github.parubok.text.multiline.MultilineLabel;
var label = new MultilineLabel();
label.setText(myText); // set text - possibly requiring multiline presentation
label.setPreferredWidthLimit(330); // the label's preferred width won't exceed 330 pixels
label.setLineSpacing(1.2f); // relative spacing between adjacent text lines
label.setMaxLines(30); // limit the label to 30 lines of text
label.setBorder(new EmptyBorder(10, 5, 10, 5));
label.setSeparators(Set.of(' ', '/', '|', '(', ')')); // allow separators other than space
panel.add(label); // add label to its parent container
```A demo application is provided. See `io.github.parubok.text.multiline.demo.Demo`.
![alt tag](https://raw.github.com/parubok/multiline-label/master/wiki/images/demo.png)
This library is packaged as a Java 9 module `io.github.parubok.text.multiline` (with a single dependency on a system module `java.desktop`).
This project has no external dependencies (except JUnit 5, for testing).
Requires Java 11 or later.
### License
This project is licensed under [Apache License, version 2.0](https://www.apache.org/licenses/LICENSE-2.0)
### Installation
Releases are available in [Maven Central](https://repo1.maven.org/maven2/io/github/parubok/multiline-label/)
#### Maven
Add this snippet to the pom.xml `dependencies` section:
```xml
io.github.parubok
multiline-label
1.20```