Open-source News

How to beautify your Java applications

opensource.com - Fri, 03/18/2022 - 15:00
How to beautify your Java applications Seth Kenlon Fri, 03/18/2022 - 03:00 Up Register or Login to like.

What's not to love about Java?

I love that Java lets me write applications on one platform and run them on other platforms. You don't have to mess around with platform-specific SDKs, using a different library for that one platform, or inserting little code hacks to make that other platform behave. To me, that's how easy all modern programming ought to be. There's great infrastructure around Java, too, like the Maven build system and SDKMan.

But there's one thing about Java I don't love: the look and feel of its default GUI toolkit, called Swing. While some people feel there's a charming nostalgia to Swing, for the modern computerist, it can look a little dated.

Fortunately, that's an easy problem to solve. Java is a programming language, so if you're writing an app in Java you can reprogram its look and feel using one of several Java theming libraries.

More on Java What is enterprise Java programming? Red Hat build of OpenJDK Java cheat sheet Free online course: Developing cloud-native applications with microservices arc… Fresh Java articles Default theme of Java Swing

The default theme of Java Swing hasn't changed much in the past decade. This is a screenshot of an example Java app from 2006—or is it 2022?

Hard to tell.

 

You can see a simpler version for yourself with this demo code:

package com.opensource.myexample2app;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Insets;
import javax.swing.JRadioButton;

public class App extends JFrame {

    private void run() {
        var window = new JPanel();
        window.setLayout(new BoxLayout(window, BoxLayout.X_AXIS));
        window.setBorder(new EmptyBorder(new Insets(15, 15, 15, 15)));

        JButton btn_hello = new JButton("Hello");
        btn_hello.setSize(new Dimension(80, 20));
        window.add(btn_hello);
       
        window.add(Box.createRigidArea(new Dimension(10, 15)));

        JRadioButton rad_world = new JRadioButton("World");
        rad_world.setSize(new Dimension(80, 20));
        window.add(rad_world);

        add(window);
        pack();

        setTitle("Hello world");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
    }

    public static void main(String[] args) {

        EventQueue.invokeLater(() -> {
            var app = new App();
            app.run();
            app.setVisible(true);
        });
    }
}

Run that in the Java IDE of your choice or with Java directly:

$ java App.java

The result is simple but demonstrative:

 

Look and Feel Java libraries

Java Swing gets its theme from Look and Feel (LAF) libraries.

The few that are bundled with Java suffice in a pinch, but newer ones are available, and you can bundle those libraries with your code to give your application a different theme. You can find LAF libraries by searching for "laf" on sites like Mvnrepository.com, or on popular coding sites like GitLab or GitHub.

My favorite is FlatLaf, but there are very good themes by NetBeans, IntelliJ, and many others under a variety of different licenses to fit any project.

The easiest way to use one of these libraries is to add it to Maven, then make minor modifications to your code to invoke the theme.

First, add the library to Maven:

<dependencies>
  <dependency>
    <groupId>com.formdev</groupId>
    <artifactId>flatlaf</artifactId>
    <version>2.0.1</version>
  </dependency>
</dependencies>

Next, import the Java UIManager library and the LAF theme you're using to your project.

import com.formdev.flatlaf.FlatLightLaf;
import javax.swing.UIManager;

In the class that creates your GUI, use UIManager to set the application's look and feel:

try {
    UIManager.setLookAndFeel( new FlatLightLaf() );
} catch( Exception ex ) {
    System.err.println( "Failed to initialize theme. Using fallback." );
}

That's it! Launch your application to see the new look and feel.

 

Flatlaf happens to have variant themes, so you can change FlatLightLaf to FlatDarkLaf for a dark theme:

 

Or use FlatIntelliJLaf for an IntelliJ-like look and feel:

 

Or FlatDarculaLaf for a dark IntelliJ look and feel:

 

Looking good, Java

Java Swing is an easy toolkit to use. It's been well maintained for two decades, and it provides a great desktop experience.

With look and feel libraries, Swing can look good, too.

Programming in Java doesn't have to be ugly. Follow these simple steps to spruce up Java Swing.

Java What to read next This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. Register or Login to post a comment.

How to Disable ‘su’ Access for Sudo Users

Tecmint - Fri, 03/18/2022 - 13:32
The post How to Disable ‘su’ Access for Sudo Users first appeared on Tecmint: Linux Howtos, Tutorials & Guides .

The su command is a special Linux command that allows you to run a command as another user and group. It also allows you to switch to the root account (if run without any

The post How to Disable ‘su’ Access for Sudo Users first appeared on Tecmint: Linux Howtos, Tutorials & Guides.

Boston University sees success with new educational tools built with Red Hat OpenShift Data Science

Red Hat News - Fri, 03/18/2022 - 12:00

Introducing students to modern computing systems can be complicated and challenging. When Boston University faculty members Jonathan Appavoo, computer science (CS) professor, and Orran Krieger, electrical and computer engineering (ECE) professor, were looking for a new, simplified way to educate their students on the critical concepts of computing systems, they turned to Red Hat OpenShift Data Science.

Linux 5.18 To Bring Many Random Number Generator Improvements

Phoronix - Fri, 03/18/2022 - 12:00
WireGuard lead developer Jason Donenfeld has recently been spearheading many improvements to the Linux kernel's random number generator (RNG) code and building off the work found in Linux 5.17, the Linux 5.18 kernel will bring a lot more on this front...

Rust Patches For The Linux Kernel Updated A Fifth Time With New Features

Phoronix - Fri, 03/18/2022 - 02:38
Miguel Ojeda who has been leading the Rust programming language support for the Linux kernel today posted his fifth spin of this patch series providing the optional Rust integration for the Linux kernel that includes example driver code...

Linux 5.18 To Fix Thermal Policy Handling For Select Newer HP Omen Laptops

Phoronix - Fri, 03/18/2022 - 01:45
Since the end of last year with Linux 5.16 there has been support for setting the thermal/performance preference with newer HP Omen laptops having ACPI Platform Profile support. This allows for toggling between cool / balanced / performance modes. Now for Linux 5.18 the HP-WMI driver is being improved upon for handling some newer laptops that have a different thermal policy interface...

AMD Now Backing AlmaLinux As This Increasingly Popular RHEL/CentOS Alternative

Phoronix - Thu, 03/17/2022 - 21:30
AMD is now among the latest companies backing the AlmaLinux OS Foundation for that increasingly popular free build derived from the Red Hat Enterprise Linux sources now that CentOS 8 is end-of-life...

AMD FidelityFX Super Resolution 2.0 Debuts

Phoronix - Thu, 03/17/2022 - 21:16
Last year AMD announced FidelityFX Super Resolution for high performance, spatial upscaling for video games across platforms. Today ahead of GDC week AMD announced FidelityFX Super Resolution 2.0...

LF Energy: Solving the Problems of the Modern Electric Grid Through Shared Investment

The Linux Foundation - Thu, 03/17/2022 - 21:00

Arresting climate change is no longer an option but a must to save the planet for future generations. The key to doing so is to transition off fossil fuels to renewable energy sources and to do so without tanking economies and our very way of life. 

The energy industry sits at the epicenter of change because energy makes everything else run. And inside the energy industry is the need for a rapid transition to electrification and our vast power grids. Like it or not, utilities face existential decisions on transforming themselves while delivering ever more power to more people without making energy unaffordable or unavailable.

The challenges are daunting:

  • How to move away from fossil fuels without crashing the global economy that is fueled by energy?
  • Is it possible to speed up the modernization of the electric grid without spending trillions of dollars?
  • Can this be done while ensuring that power is safe, reliable, and affordable for all?

These are all significant problems to solve and represent 75% of the problem in combating climate change through decarbonization. In the Linux Foundation’s latest case study, Paving the Way to Battle Climate Change: How Two Utilities Embraced Open Source to Speed Modernization of the Electric Grid, LF Energy explores the opportunities for digital transformation within electric utility providers and the role of open source technologies in accelerating the transition.

Download Case Study Open Source meets climate change challenges with LF Energy

The growth of renewable energy sources is making the challenges of modernizing the modern grid more complicated. In the past, energy flowed from coal and gas generating plants onto the big Transmission System Operator (TSO) lines and then to the smaller Distribution System Operator (DSO) lines to be transformed into a lower voltage suitable for homes and businesses. 

But now, with solar panels and wind turbines increasingly feeding electricity back into the grid, the flow of power is two-way.

This seismic shift requires a new way of thinking about generating, distributing, and consuming energy. And it’s one that open source can help us navigate.

Today, energy travels in all directions, from homes and businesses, and from wind and solar farms, through the DSOs to the TSOs, and back again. This fundamental change in how power is generated and consumed has resulted in a much more complicated system that utilities must administer. They’ll require new tools to guarantee grid stability and manage the greater interaction between TSOs and DSOs as renewables grow.

Open source software allows utilities to keep up with the times while lowering expenses. It also gives utilities a chance to collaborate on common difficulties rather than operating in isolation. 

The communities developing LF Energy’s various software projects provide those tools. It’s helping utilities to speed up the modernization of the grid while reducing costs. And it’s giving them the ability to collaborate on shared challenges rather than operate in silos.

Two European utility providers, the Netherlands’ Alliander and France’s RTE are leading the change by upgrading their systems – markets, controls, infrastructure, and analytics – with open source technology.

RTE (a TSO) and Alliander (a TSO) joined forces initially (as members of the Linux Foundation’s LF Energy projects) because they faced the same problem: accommodating more renewable energy sources in infrastructures not originally designed for them and doing it at the speed and scale required. And while they are not connected due to geography, the problems they are tackling apply to all TSOs and DSOs worldwide.

Two electric utility providers collaborate on shared technology investments, together

The way that Alliander and RTE collaborated via LF Energy on a project known as Short Term Forecasting, or OpenSTEF, illustrates the benefits of open source collaboration to tackle common problems. 

“Short-term forecasting, for us, is the core of our existence,” According to Alliander’s Director of System Operations, Arjan Stam. “We need to know what will be happening on the grid. That’s the only way to manage the power flows,” and to configure the grid to meet customer needs.“The same is true for RTE and “every grid operator across the world,” says Lucian Balea, RTE’s Director of Open Source. 

Alliander has five people devoted to OpenSTEF, and RTE has two.

Balea says that without joining forces, OpenSTEF would develop far less quickly, and RTE may not have been able to work on such a solution in the near term.

Since their original collaboration on OpenSTEF, they have collaborated on additional LF Energy Projects, CoMPAS, and SEAPATH. 

CoMPAS is Configuration Modules for Power industry Automation Systems, which addresses a core need to develop open source software components for profile management and configuration of a power industry protection, automation, and control system. ComPAS is critical for the digital transformation of the power industry and its ability to move quickly to new technologies. It will enable a wide variety of utilities and technology providers to work together on developing innovative new solutions.

SEAPATH, Software Enabled Automation Platform and Artifacts (THerein): aims to develop a platform and reference design for an open source platform built using a virtualized architecture to automate the management and protection of electricity substations. The project is led by Alliander, with RTE and other consortium members contributing.

As we move to a decarbonized future, open source will play an increasingly important role in helping utilities meet their goals. It’s already helping them speed up the grid’s modernization, reduce costs, and collaborate on shared challenges. And it’s only going to become essential as we move toward a cleaner, more sustainable energy system.

Read Paving the Way to Battle Climate Change: How Two Utilities Embraced Open Source to Speed Modernization of the Electric Grid to see how it works and how you and your organization may leverage Open Source. Together, we can develop solutions. 

Subscribe to LF Research

The post LF Energy: Solving the Problems of the Modern Electric Grid Through Shared Investment appeared first on Linux Foundation.

Pages