如何在SWT中设计Composite

时间:2015-09-04 08:41:28

标签: java swt eclipse-rcp jface rcp

我想在A面的复合材料中放入3个固定尺寸的组。我想把图像和标签放在这个组的中间。我的示例图像和代码如下。问题是组根据标签大小调整大小,标签写在组的顶部,但我希望地方组的大小相等,以覆盖A侧的宽度,标签应该是组的垂直中间。

<?php
$jd = cal_to_jd(CAL_GREGORIAN,date("m"),date("d"),date("Y"));
$presentday = jddayofweek($jd,1);

$opentime = "";
$closetime = "";

switch($presentday) {

    case 'Monday':
    $opentime = date("g:i a", strtotime($hour_mon_open));
    $closetime = date("g:i a", strtotime($hour_mon_close));
    break;

    case 'Tuesday':
    $opentime = date("g:i a", strtotime($hour_tue_open));
    $closetime = date("g:i a", strtotime($hour_tue_close));    
    break;

    case 'Wednesday':
    $opentime = date("g:i a", strtotime($hour_wed_open));
    $closetime = date("g:i a", strtotime($hour_wed_close));
    break;

    case 'Thursday':
    $opentime = date("g:i a", strtotime($hour_thu_open));
    $closetime = date("g:i a", strtotime($hour_thu_close));
    break;

    case 'Friday':
    $opentime = date("g:i a", strtotime($hour_fri_open));
    $closetime = date("g:i a", strtotime($hour_fri_close));
    break;

    case 'Saturday':
    $opentime = date("g:i a", strtotime($hour_sat_open));
    $closetime = date("g:i a", strtotime($hour_sat_close));
    break;

    case 'Sunday':
    $opentime = date("g:i a", strtotime($hour_sun_open));
    $closetime = date("g:i a", strtotime($hour_sun_close));
    break;

    default:
    break;        
}

$currentHours = date("g:i a", time());
$date1 = DateTime::createFromFormat('H:i a', $currentHours);
$date2 = DateTime::createFromFormat('H:i a', $opentime);
$date3 = DateTime::createFromFormat('H:i a', $closetime);

if ($date1 > $date2 && $date1 < $date3) {
    echo "Open now";
} else {
    echo "Closed now";
}
?>

enter image description here

2 个答案:

答案 0 :(得分:0)

一种方法是将GridLayout用于父组合,并告诉它使用3个相等大小的列:

Composite dynamicDataComp = toolkit.createComposite(sectionClientA);

dynamicDataComp.setLayout(new GridLayout(3, true));

答案 1 :(得分:0)

使用GridLayout并将列设置为宽度:

Composite dynamicDataComp = new Composite(parent, SWT.NONE);
    dynamicDataComp.setLayout(new GridLayout(3, true));
    dynamicDataComp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

Group group_incom = new Group(dynamicDataComp, SWT.NONE);
        group_incom.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        group_incom.setLayout(new RowLayout());

//...