This PR is related to BAEL-7188 (#15271)

* Update pom.xml

Adding core-java-swing

* This commit is related to BAEL-7188

This commit aims to add a new module named "core-java-swing".
This commit is contained in:
MohamedHelmyKassab 2023-11-24 18:45:14 +02:00 committed by GitHub
parent c7ef62ee99
commit b80ceb7ceb
4 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>core-java-string-swing</artifactId>
<name>core-java-string-swing</name>
<packaging>jar</packaging>
<parent>
<groupId>com.baeldung.core-java-modules</groupId>
<artifactId>core-java-modules</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<properties>
<maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -0,0 +1,55 @@
package com.baeldung.customfont;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
public class CustomFonts {
public static void main(String[] args) {
usingCustomFonts();
}
public static void usingCustomFonts() {
final GraphicsEnvironment GE = GraphicsEnvironment.getLocalGraphicsEnvironment();
final List<String> AVAILABLE_FONT_FAMILY_NAMES = Arrays.asList(GE.getAvailableFontFamilyNames());
try {
final List<File> LIST = Arrays.asList(
new File("font/JetBrainsMono/JetBrainsMono-Thin.ttf"),
new File("font/JetBrainsMono/JetBrainsMono-Light.ttf"),
new File("font/Roboto/Roboto-Light.ttf"),
new File("font/Roboto/Roboto-Regular.ttf"),
new File("font/Roboto/Roboto-Medium.ttf")
);
for (File LIST_ITEM : LIST) {
if (LIST_ITEM.exists()) {
Font FONT = Font.createFont(Font.TRUETYPE_FONT, LIST_ITEM);
if (!AVAILABLE_FONT_FAMILY_NAMES.contains(FONT.getFontName())) {
GE.registerFont(FONT);
}
}
}
} catch (FontFormatException | IOException exception) {
JOptionPane.showMessageDialog(null, exception.getMessage());
}
JFrame frame = new JFrame("Custom Font Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new FlowLayout());
JLabel label1 = new JLabel("TEXT1");
label1.setFont(new Font("Roboto Medium", Font.PLAIN, 17));
JLabel label2 = new JLabel("TEXT2");
label2.setFont(new Font("JetBrainsMono-Thin", Font.PLAIN, 17));
frame.add(label1);
frame.add(label2);
frame.pack();
frame.setVisible(true);
}
}

View File

@ -183,6 +183,7 @@
<module>core-java-string-algorithms</module>
<module>core-java-string-algorithms-2</module>
<module>core-java-string-apis</module>
<module>core-java-swing</module>
<module>core-java-string-apis-2</module>
<module>core-java-string-conversions</module>
<module>core-java-string-conversions-2</module>