Skip to main content



      Home
Home » Newcomers » Newcomers » eclipse gridlayout frustration
eclipse gridlayout frustration [message #154057] Fri, 26 May 2006 01:31
Eclipse UserFriend
Originally posted by: paddy.mahoney.gmail.com

Hi all,
I have been struggling for a while attempting to get the GridLayout to
work properly. Specifically, I am attempting to add a GridLayout to a
Group. For some reason or other, none of the controls I add are visible.
Only the group itself is visible, but none of the internal buttons I
add. Initially, I thought this occured do to my practice of adding the
controls with a loop structure. However, it looks as if I am simply
incapable of getting it to work period :)
Ill post the offending snippet of code.
Ubuntu Linux and Windows Eclipse 3.1.2

/**
*start code snippet
**/

package gui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;

public class ChordGui implements Runnable{
private Display display=null;
private Shell shell=null;
private Group rootGroup=null;
private Button noteAb=null;
private Button noteA=null;
private Button noteAp=null;
private Button noteBb=null;
private Button noteB=null;
private Button noteC=null;
private Button noteCp=null;
private Button noteDb=null;
private Button noteD=null;
private Button noteDp=null;
private Button noteEb=null;
private Button noteE=null;
private Button noteF=null;
private Button noteFp=null;
private Button noteGb=null;
private Button noteG=null;
private Button noteGp=null;

public void run() {
drawControls();
//startListeners();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}

private void drawControls() {
display=Display.getDefault();
shell=new Shell(display);
shell.setText("The Chordalyzer");
shell.open();

drawRootGroup();
}

private void drawRootGroup() {

GridLayout gridLayout = new GridLayout();
gridLayout.makeColumnsEqualWidth=true;
gridLayout.horizontalSpacing=0;
gridLayout.verticalSpacing=0;
gridLayout.marginHeight=15;
gridLayout.marginWidth=15;
gridLayout.numColumns=3;

rootGroup=new Group(shell,SWT.SHADOW_ETCHED_OUT);
rootGroup.setText("Root Note");
rootGroup.setLocation(10,10);
rootGroup.setSize(500,500);
rootGroup.setLayout(gridLayout);

GridData gridData=new GridData(GridData.FILL_BOTH);
gridData.horizontalSpan=1;
gridData.verticalSpan=1;

{
noteAb=new Button(rootGroup,SWT.TOGGLE);
noteA=new Button(rootGroup,SWT.TOGGLE);
noteAp=new Button(rootGroup,SWT.TOGGLE);
noteBb=new Button(rootGroup,SWT.TOGGLE);
noteB=new Button(rootGroup,SWT.TOGGLE);
noteC=new Button(rootGroup,SWT.TOGGLE);
noteCp=new Button(rootGroup,SWT.TOGGLE);
noteDb=new Button(rootGroup,SWT.TOGGLE);
noteD=new Button(rootGroup,SWT.TOGGLE);
noteDp=new Button(rootGroup,SWT.TOGGLE);
noteEb=new Button(rootGroup,SWT.TOGGLE);
noteE=new Button(rootGroup,SWT.TOGGLE);
noteF=new Button(rootGroup,SWT.TOGGLE);
noteFp=new Button(rootGroup,SWT.TOGGLE);
noteGb=new Button(rootGroup,SWT.TOGGLE);
noteG=new Button(rootGroup,SWT.TOGGLE);
noteGp=new Button(rootGroup,SWT.TOGGLE);
}
{
noteAb.setText("Ab");
noteA.setText("A");
noteAp.setText("A#");
noteBb.setText("Bb");
noteB.setText("B");
noteC.setText("C");
noteCp.setText("C#");
noteDb.setText("Db");
noteD.setText("D");
noteDp.setText("D#");
noteEb.setText("Eb");
noteE.setText("E");
noteF.setText("F");
noteFp.setText("F#");
noteGb.setText("Gb");
noteG.setText("G");
noteGp.setText("G#");
}

Button[] rootNoteButtons={noteAb,noteA,
noteAp,noteBb,noteB,noteC,noteCp,
noteDb,noteD,noteDp,noteEb,noteE,
noteF,noteFp,noteGb,noteG,noteGb};

for (int xx=0;xx<rootNoteButtons.length;xx++) {
rootNoteButtons[xx].setLayoutData(gridData);
}

}

public static void main(String[] args) {
ChordGui main=new ChordGui();
main.run();
}
}


/**
*end code snippet
**/
what am I doing wrong so that none of the buttons are being displayed in
the group in the layout?

in a test class, when I recreate the intended appearance with the visual
editor, the buttons show in the preview shell, but not when I actually
run the program. This behaviour occurs across both operating systems
that I use.

some general code pointers would be appreciated also :)

much love,
Pat Mahoney
Previous Topic:Java programming question: Viewing .DOC files in Eclipse
Next Topic:BIRT perspective is not available with latest eclipse and birt installaion
Goto Forum:
  


Current Time: Mon Jun 02 23:12:28 EDT 2025

Powered by FUDForum. Page generated in 0.07761 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top