Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] Coloring buttons and other assorted controls

I'm trying make my screens look more alive by trying to repaint things, however atm I'm only finding that my buttons and toolbars won't change color (I'm using the windows version). Labels, shells and composites work okay. I've attached some test code.

package test;

// $Id:$
// Copyright (C) 2001, 2002, 2003, Forge Research Pty. Limited. All rights 
// reserved.
// www.forge.com.au

import au.com.forge.sys.timesheet.client.Controller;

import org.apache.log4j.ForgeLogger;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ViewForm;

import java.util.ArrayList;
import java.util.Collection;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * 
 *
 * @author minhc
 * @version $Revision:$
 */
public class
Test
{
   // Constants and variables
   // ----------------------------------------------------------------------
   

   
   // Constructors
   // ----------------------------------------------------------------------
  
   /**
    * Default Ctor
    */
   public
   Test()
   {
   }
   
   // Class methods
   // ----------------------------------------------------------------------
   public static void
   main(String[] args)
   throws Exception
   {
      final Display display = new Display();
      Shell shell = new Shell (display);

      final Color backgroundColor = new Color(display, 190, 231, 250);
      final Color foregroundColor = new Color(display, 100, 188, 253);

      shell.setBackground(backgroundColor);

      final ViewForm mainForm = new ViewForm(shell, SWT.NONE);
      mainForm.setBackground(backgroundColor);
      ToolBar toolBar = new ToolBar(mainForm, SWT.FLAT | SWT.BORDER);
      toolBar.setBackground(backgroundColor);
      mainForm.setTopLeft(toolBar);
      final ToolItem connectToolItem = new ToolItem(toolBar, SWT.PUSH | SWT.BORDER);
      connectToolItem.setText("Connect");

      Button b = new Button(mainForm, SWT.NONE);
      b.setText("Ok");
      b.setBackground(foregroundColor);
      b.setForeground(foregroundColor);
      mainForm.setContent(b);

      Label l = new Label(mainForm, SWT.NONE);
      l.setText("Label");
      l.setBackground(foregroundColor);
      mainForm.setTopCenter(l);


      mainForm.pack();
      shell.pack();
      shell.open();

      shell.redraw();
	   while (!shell.isDisposed ()) {
		   if (!display.readAndDispatch ()) display.sleep ();
	   }
	   display.dispose ();
      backgroundColor.dispose();
      foregroundColor.dispose();
   }


   // Instance methods
   // ----------------------------------------------------------------------
}

Back to the top