Swing
Java Swing is a GUI toolkit for building desktop applications in Java. It provides standard components like windows (JFrame
), panels, buttons, and more, all written in pure Java for cross-platform consistency. In modern apps, you might want to display web content (HTML, CSS, JavaScript) alongside your traditional Swing components. With Equo Chromium you can do just that.
Using Equo Chromium with the Swing toolkit
To use Equo Chromium with the Swing toolkit, follow these steps:
1. Import required classes
Start by importing the necessary Java Swing and Equo Chromium classes:
import java.awt.BorderLayout;
import javax.swing.JFrame;
import com.equo.chromium.ChromiumBrowser;
2. Create and configure the frame
Create a JFrame
, set its close operation to DISPOSE_ON_CLOSE
. This is so that Chromium processes are properly terminated when the window is closed.
public class SwingExample extends JFrame {
public SwingExample() {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
3. Instantiate the browser
Use ChromiumBrowser.swing(…)
to embed the browser into the Swing container, then apply a layout. Using BorderLayout
is recommended to allow the browser to fill the frame.
ChromiumBrowser browser = ChromiumBrowser.swing(
getContentPane(),
BorderLayout.CENTER,
"https://docs.equo.dev"
);
setSize(800, 600);
setVisible(true);
public static void main(String[] args) {
new SwingExample();
}
4. Set a background color
You can customize the background color of the browser component using Java AWT
:
import java.awt.Color;
import java.awt.Component;
Object component = browser.getUIComponent();
((Component) component).setBackground(new Color(0, 0, 255, 255));
Be sure the component you’re modifying is properly cast to |