From b80ceb7cebf411c797015023b37e6815bfda520a Mon Sep 17 00:00:00 2001 From: MohamedHelmyKassab <137485958+MohamedHelmyKassab@users.noreply.github.com> Date: Fri, 24 Nov 2023 18:45:14 +0200 Subject: [PATCH] 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". --- core-java-modules/core-java-swing/pom.xml | 21 +++++++ .../com/baeldung/customfont/CustomFonts.java | 55 ++++++++++++++++++ .../target/classes/org/example/Main.class | Bin 0 -> 2912 bytes core-java-modules/pom.xml | 1 + 4 files changed, 77 insertions(+) create mode 100644 core-java-modules/core-java-swing/pom.xml create mode 100644 core-java-modules/core-java-swing/src/main/java/com/baeldung/customfont/CustomFonts.java create mode 100644 core-java-modules/core-java-swing/target/classes/org/example/Main.class diff --git a/core-java-modules/core-java-swing/pom.xml b/core-java-modules/core-java-swing/pom.xml new file mode 100644 index 0000000000..28228ebb29 --- /dev/null +++ b/core-java-modules/core-java-swing/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + core-java-string-swing + core-java-string-swing + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + + + 20 + 20 + UTF-8 + + + \ No newline at end of file diff --git a/core-java-modules/core-java-swing/src/main/java/com/baeldung/customfont/CustomFonts.java b/core-java-modules/core-java-swing/src/main/java/com/baeldung/customfont/CustomFonts.java new file mode 100644 index 0000000000..28e0da84ae --- /dev/null +++ b/core-java-modules/core-java-swing/src/main/java/com/baeldung/customfont/CustomFonts.java @@ -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 AVAILABLE_FONT_FAMILY_NAMES = Arrays.asList(GE.getAvailableFontFamilyNames()); + try { + final List 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); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-swing/target/classes/org/example/Main.class b/core-java-modules/core-java-swing/target/classes/org/example/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..5914458bc4b1b959f8d4cc18270605acd2f4249e GIT binary patch literal 2912 zcmai0+jA3D82@dXWYe$+6hSHlQxI)RN(2FwVzrb614)at7F#cMn{JbZBpY`(wDo?! z-|yi4ikBH@d`ZEMjx#GmpU?u?9t5JZcLkcMSa+_JMV zV@5BO@ETC z^;yGBSs6XQBsbg{N&T08k8rkH!^K$Rnd&>Cn|XaAZzQauo6rkpes(}F7>1Uj3x)`j1X?Yh>D{cZWZV7L}V80BFqa(sti0-Ol zp>8~3Gq*uZFv$M0<64EVIA=KSO{5UU(IFm&hAGh3I>&JL8&i5Y@Al^{#~3ULATkvM zO=mJf4`%JSGLw00I;GEAWdb6HW??C>p#X}v(2~dEz-c&vx0lw7OpDzkES4^eIi*h+ z`5=gX|8V@)VGc?Q9YK@{La!miUMmSGO^XRI!;~&D0g?<@=-#8@UfjoqU`YRl1`dk{ zs{VEa@eo5=G=t>S5yyK(!=reNEu~LRa=0`cY@sv_qj+IcC_ka$NpUIoN_ytF*mzpQ zGkBIzVPqqwV{#sgM2|&A`0BSNxmuAji^f2?Fk#rkVqP;cc@2!{wkg)tO`n@H*%#zp zaNqRMQbFE3YZuMsYJW*jx}Bx&>c+8MWm7pZI4~^2Sk(Wt+LB5R4UZ>><7rN?#XV0g z!Q?gJ?bk<}P%~=X#V&3DalLUU({v!tF}vV#i7Ss%>-$FflBvFZsra~vaXitNPNqi3 z2l~=+wyl3kAfHo3npxZrR1Wa+GxFR2!I#*p^LKCnFV6OCsh08Z1!vpqt!s0ymqspM zTBPw_6=KVWT;d_Em#Vc44OwM7V~9JE`4S%u+eGrw!B2}Oev|;s-~kcf^Es|!d@FqW zyXK&LL!t@K^C{Rs2ruxdc>;J5FLBj^m+=aBgz^slg`DpU)CFDf(Id2)IZ+q%eRvhG zalb`;+j#m-QBnb#2%Ld-sH=k3GfY|VJG75B&-2l`aSq|3QJ_3Z}ns5rC zF0o1-J$?SC)6mjNw1VL?7@f!XXsbSlOgb8Nc-jHHQ-w%u3GvC}#=v4OP-Q+G49JMbnp;eA|zFK{KkMkmgq3qN8jenB_R zVHcore-java-string-algorithms core-java-string-algorithms-2 core-java-string-apis + core-java-swing core-java-string-apis-2 core-java-string-conversions core-java-string-conversions-2