Question

alt text

I have inherited development of a Java/SWT application running on Windows only. One of the feature requests that I need to scope is a Google-chrome-type title bar in place of the SWT windows title bar. The application's tabs appear at the same level as the window control buttons.

My understanding is that I will need to:

  • write a Windows widget capable of rendering the custom look and managing tabs as opposed to menus.
  • expose the Windows widget as a dll for use in Java via JNI
  • write a custom SWT widget to wrap it and expose the tab management interface.

I have a lot of experience with Java programming, GUI programming with Swing/AWT, and non-GUI C# programming. Windows GUI programming and SWT are new to me so I'm not sure where to start. The best I have found so far is a 2001 article on writing your own SWT widget.

My biggest unknown is the best way to implement a custom Windows application-window.

Was it helpful?

Solution

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

OTHER TIPS

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 ();
    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top