how to place other Widgets (ie.Label,Button) on Sash? urgent

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

how to place other Widgets (ie.Label,Button) on Sash? urgent

Postby jackyustb » Thu Nov 16, 2006 5:41 pm

Now i'm coding with SWT/JFace.
I wanna show text message and add button on Sash (org.eclipse.swt.widgets.Sash),how to do?
jackyustb
 
Posts: 5
Joined: Thu Nov 16, 2006 5:39 pm

Postby Konstantin.Scheglov » Fri Nov 17, 2006 1:48 am

You don't want to use Sash, you should use SashForm.
Just first widget on it, then:
1. drop second in Tree
2. or select SashForm and drop second widget near to the border of SashForm. A little tricky, but SashForm fill itself with children widgets, so you need special way for dropping new children.
Konstantin.Scheglov
Moderator
 
Posts: 186
Joined: Tue Oct 18, 2005 8:11 pm
Location: Russian Federation, Lipetsk

but i only hope show some messages on sash in a sashform.

Postby jackyustb » Mon Nov 20, 2006 8:42 pm

i hope to show some tip messages on sash in a sashform which contains two children ,one is Tableview on its top, another is Text on its bottom. the sash in the middle separate them.
When i select one item in the Tableview,i wanna show the item's main content in the Text widget and tip message on the sash.
how to do?
Konstantin.Scheglov wrote:You don't want to use Sash, you should use SashForm.
Just first widget on it, then:
1. drop second in Tree
2. or select SashForm and drop second widget near to the border of SashForm. A little tricky, but SashForm fill itself with children widgets, so you need special way for dropping new children.
jackyustb
 
Posts: 5
Joined: Thu Nov 16, 2006 5:39 pm

Re: but i only hope show some messages on sash in a sashfor

Postby Eric Clayberg » Fri Nov 24, 2006 5:48 am

jackyustb wrote:i hope to show some tip messages on sash in a sashform which contains two children ,one is Tableview on its top, another is Text on its bottom. the sash in the middle separate them.
When i select one item in the Tableview,i wanna show the item's main content in the Text widget and tip message on the sash.
how to do?

You would need to get the children of the SashForm, find the Sash widget and then set its tooltip using setToolTipText().

General questions about using SWT should be posted to the Eclipse SWT newsgroup.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: but i only hope show some messages on sash in a sashfor

Postby jackyustb » Wed Nov 29, 2006 5:50 pm

Eric Clayberg wrote:
jackyustb wrote:i hope to show some tip messages on sash in a sashform which contains two children ,one is Tableview on its top, another is Text on its bottom. the sash in the middle separate them.
When i select one item in the Tableview,i wanna show the item's main content in the Text widget and tip message on the sash.
how to do?

You would need to get the children of the SashForm, find the Sash widget and then set its tooltip using setToolTipText().

General questions about using SWT should be posted to the Eclipse SWT newsgroup.

Children of the SashForm contains the Sash?
jackyustb
 
Posts: 5
Joined: Thu Nov 16, 2006 5:39 pm

Re: but i only hope show some messages on sash in a sashfor

Postby Eric Clayberg » Wed Nov 29, 2006 7:46 pm

jackyustb wrote:Children of the SashForm contains the Sash?

Yes.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: but i only hope show some messages on sash in a sashfor

Postby Makaron » Mon Sep 08, 2008 4:56 am

Eric Clayberg wrote:
jackyustb wrote:Children of the SashForm contains the Sash?

Yes.


Sorry, but the children of SashForm don't contain the Sash: consider the following example

http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/DemonstratesSashForm.htm

which I modified only slightly, to see, if the SashForm's children contain the Sash, but it seems that only the two Buttons are children of SashForm. Here is
the modified code:

Code: Select all

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.*;

/**
* This class demonstrates SashForm
*/
public class SashFormTest {
  /**
   * Runs the application
   */
  public void run() {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("SashForm Test");
    createContents(shell);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }

  /**
   * Creates the main window's contents
   *
   * @param parent the parent window
   */
  private void createContents(Composite parent) {
    // Fill the parent window with the buttons and sash
    parent.setLayout(new FillLayout());

    // Create the SashForm and the buttons
    SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL);
    new Button(sashForm, SWT.PUSH).setText("Left");
    new Button(sashForm, SWT.PUSH).setText("Right");
   

    // This is the part, where the children of SashForm are printed out:
    Control[] controls = sashForm.getChildren();   
   
    for (Control control : controls)
    {
        System.out.println(control.getClass().getName());
    }
   
  }

  /**
   * The application entry point
   *
   * @param args the command line arguments
   */
  public static void main(String[] args) {
    new SashFormTest().run();
  }
}


Or maybe I'm missing something...


Have a nice day
Makaron
 
Posts: 3
Joined: Mon Sep 08, 2008 4:45 am

Re: but i only hope show some messages on sash in a sashfor

Postby Eric Clayberg » Mon Sep 08, 2008 6:01 am

First of all, let me reiterate that general questions about SWT should be posted to the Eclipse SWT newsgroup.

Makaron wrote:Sorry, but the children of SashForm don't contain the Sash

I'm sorry, but that is incorrect. The children of the SashForm most certainly include one or more Sash instances.

Makaron wrote:consider the following example

That is not a relevant example for showing what the actual children of a SashForm are.

Makaron wrote:Or maybe I'm missing something

Yes. As is always the case with a question like this, you should start by looking at the actual implementation of the SashForm class itself. There you will see quite clearly that a SashForm includes one or more Sash widgets and that they are all held in the sashes field.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: but i only hope show some messages on sash in a sashfor

Postby Makaron » Tue Sep 09, 2008 3:04 am

Eric Clayberg wrote:First of all, let me reiterate that general questions about SWT should be posted to the Eclipse SWT newsgroup.


I apologize for posting here, but this is a problem which really puzzles me. I need to get a Sash instance from SashForm to limit maximum width of a Composite in a SashForm (I have two Composites that reside on a SashForm). I read about how to do this here:

http://gretchenmoran.blogspot.com/2008/ ... nt-on.html

Makaron wrote:Or maybe I'm missing something
Eric Clayberg wrote:Yes. As is always the case with a question like this, you should start by looking at the actual implementation of the SashForm class itself. There you will see quite clearly that a SashForm includes one or more Sash widgets and that they are all held in the sashes field.


I looked at the SashForm implementation and there's indeed private field sashes, but I don't know how to get Sash instances from it; the method SashForm.getChildren() obviously doesn't return any Sash objects.


Have a nice day,

A.
Makaron
 
Posts: 3
Joined: Mon Sep 08, 2008 4:45 am

Re: but i only hope show some messages on sash in a sashfor

Postby Eric Clayberg » Tue Sep 09, 2008 4:39 am

Makaron wrote:I looked at the SashForm implementation and there's indeed private field sashes, but I don't know how to get Sash instances from it; the method SashForm.getChildren() obviously doesn't return any Sash objects.

Very easy using reflection...

Code: Select all
import java.lang.reflect.Field;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.widgets.Sash;

public class SashFormHelper {
   public static Sash[] getSashes(SashForm sf) {
      final Field fields[] = sf.getClass().getDeclaredFields();
      for (int i = 0; i < fields.length; ++i) {
         if ("sashes".equals(fields[i].getName())) {
            try {
               fields[i].setAccessible(true);
               return (Sash[]) fields[i].get(sf);
            } catch (IllegalAccessException ex) {
            }
         }
      }
      return null;
   }
}

And then to modify your example...

Code: Select all
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.*;

/**
* This class demonstrates SashForm
*/
public class SashFormTest {
   public SashForm sashForm;

   /**
    * Runs the application
    */
   public void run() {
      Display display = new Display();
      Shell shell = new Shell(display);
      shell.setText("SashForm Test");
      createContents(shell);
      shell.open();

      // This is the part, where the children of SashForm are printed out:
      Control[] controls = sashForm.getChildren();
      for (Control control : controls) {
         System.out.println(control.getClass().getName());
      }

      // Note that Sashes don't exist until the window is open
      Sash[] sashes = SashFormHelper.getSashes(sashForm);
      for (Sash sash : sashes) {
         sash.setToolTipText("I am a Sash");
         System.out.println(sash.getClass().getName());
      }

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

   /**
    * Creates the main window's contents
    *
    * @param parent
    *            the parent window
    */
   private void createContents(Composite parent) {
      // Fill the parent window with the buttons and sash
      parent.setLayout(new FillLayout());

      // Create the SashForm and the buttons
      sashForm = new SashForm(parent, SWT.HORIZONTAL);
      new Button(sashForm, SWT.PUSH).setText("Left");
      new Button(sashForm, SWT.PUSH).setText("Right");
   }

   /**
    * The application entry point
    *
    * @param args
    *            the command line arguments
    */
   public static void main(String[] args) {
      new SashFormTest().run();
   }
}
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: but i only hope show some messages on sash in a sashfor

Postby Makaron » Tue Sep 09, 2008 6:23 am

Eric Clayberg wrote:
Makaron wrote:I looked at the SashForm implementation and there's indeed private field sashes, but I don't know how to get Sash instances from it; the method SashForm.getChildren() obviously doesn't return any Sash objects.

Very easy using reflection...


Thank you very much, this solution really works, you saved my day.

I wasn't aware of the getClass().getDeclaredFields() method, I still have to learn much Java. But now I understand one new concept, namely, how to get to the private fields - thanks to you being so kind.

Best regards,

A.
Makaron
 
Posts: 3
Joined: Mon Sep 08, 2008 4:45 am

Re: but i only hope show some messages on sash in a sashfor

Postby Eric Clayberg » Tue Sep 09, 2008 1:33 pm

Makaron wrote:Thank you very much, this solution really works, you saved my day.

You're welcome. You should also check out the eclipse.platform.swt newsgroup as teh best place to ask most SWT-related questions.

Makaron wrote:I wasn't aware of the getClass().getDeclaredFields() method.

Java reflection can be a lot of fun. It's like the extra key hidden under the mat that will get you into almost any locked door. ;-)
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 1 guest