How to implement a Google-chrome-like title bar for Java SWT application How to implement a Google-chrome-like title bar for Java SWT application google-chrome google-chrome

How to implement a Google-chrome-like title bar for Java SWT application


You can create a Shell instance without a TITLE flag and then render Google-chrome-like tabs manually. This way you can even create a non-rectangular windows


when dealing with things that are not yet in the JNI layer of SWT, you should always remember that you can quickly prototype things with JNA. When the JNA prototype, then you can either extend SWT's native interface or create your own separate JNI layer (This is an approach that worked well for me a number of times when dealing with SWT Carbon/Cocoa widgets)


I recommend creating a shell without a Trim like so:

new Shell (display, SWT.NO_TRIM);

This would create a shell without the title bar. Subsequently you can make your own close/minimize/maximize buttons.

Here is an example that spawns a lone progress bar without the title bar business.

enter image description here

import org.eclipse.swt.SWT;import org.eclipse.swt.layout.FormAttachment;import org.eclipse.swt.layout.FormData;import org.eclipse.swt.layout.FormLayout;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.ProgressBar;import org.eclipse.swt.widgets.Shell;public class ProgressBarGui {    Display display;    Shell shell;    public static void main (String [] args) {        final Display display = new Display ();        final Shell shell = new Shell (display, SWT.NO_TRIM);        //Something to put into shell.        shell.setLayout (new FormLayout ());        ProgressBar proBar = new ProgressBar (shell, SWT.SMOOTH);        proBar.setSelection (50);        FormData progBarData = new FormData (100, 20);        progBarData.top = new FormAttachment (0);        progBarData.left = new FormAttachment (0);        proBar.setLayoutData (progBarData);        //recompute shell's size and position to fit widget.        shell.pack ();        shell.open ();        while (!shell.isDisposed ()) {            if (!display.readAndDispatch ())                display.sleep ();        }        // region.dispose();        display.dispose ();    }}