1

SWTJFaceTableViewerコンポーネントを使用してデータのリストを表示しています。IColorProviderカスタムの前景色と背景色を提供するためにを実装しました。ほとんどの場合、明るい背景色で黒の前景テキストを提供します。ただし、場合によっては、前景のテキストが白の暗い背景色を使用します。これは、選択色が淡い青であるという点でWindows7で問題を引き起こします。

Windows 7で起こっていることは、テーブル内の暗い色のアイテム(行選択)が選択されている場合、背景色は淡い青色の選択色です。ただし、前景色は白のままで見えません(下図1参照)。

図1:JFaceSWTTableViewer-Windows7で選択された行

  1. まず、私はここで何か間違ったことをしていますか?

  2. 次に、これを修正するために次のことを試みました(HOTイベントペインティングに関するアイデアはありますか?):

    table.addListener(SWT.EraseItem, new Listener() {
        public void handleEvent(Event event) {
            System.out.println(event);
            boolean selected = (event.detail & SWT.SELECTED) == 0;
    
            event.detail &= ~SWT.HOT;
            TableItem item = (TableItem) event.item;
            int clientWidth = table.getClientArea().width;
            GC gc = event.gc;
            Color oldForeground = gc.getForeground();
            Color oldBackground = gc.getBackground();
            if (selected) {
                gc.setForeground(ColourHelper.WHITE);
                gc.setBackground(ColourHelper.WHITE);
                gc.fillRectangle(0, event.y, clientWidth, event.height);
            } else {
                gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));                 
                gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_BACKGROUND));                  
                gc.fillGradientRectangle(0, event.y, clientWidth, event.height, true);
            }
    
            gc.setForeground(oldForeground);
            gc.setBackground(oldBackground);
            event.detail &= ~SWT.SELECTED;
        }
    });
    

テストアプリケーションを再実行すると、次のようになります。選択した行は修正されましたが、図2に示すように、テーブル行が「ホバー」されているという問題があります。EraseItemハンドラー内でSWT.HOTイベントをキャプチャしようとしましたが、表示されません。何をするにも。

図2:JFaceSWTTableViewer-追加されたEraseItemイベントハンドラー

PaintItemイベントハンドラーを追加することはできましたが(以下に示すように)、正しくレンダリングするには、このコードにセルの配置に関する同じロジックを配置する必要があります。さらに、私のペイントイベントが発生し、正しくレンダリングされたSELECTED Windows7Colorfixをペイントします。

table.addListener(SWT.PaintItem, new Listener() {
    public void handleEvent(Event event) {

        boolean hot = (event.detail & SWT.HOT) == 0;
        if (hot) System.out.println("HOT!");
        if ((event.detail & SWT.HOT & ~SWT.SELECTED) == 0)
            return;
        event.detail &= ~SWT.HOT;
        final int TEXT_MARGIN = 3;
        GC gc = event.gc;

        gc.setForeground(ColourHelper.BLACK);
        gc.setBackground(ColourHelper.BLACK);

        TableItem item = (TableItem) event.item;
        item.setBackground(ColourHelper.BLACK);
        item.setForeground(ColourHelper.BLACK);
        String text = item.getText(event.index);
        int yOffset = 0;
        if (event.index == 1) {
            Point size = event.gc.textExtent(text);
            yOffset = Math.max(0, (event.height - size.y) / 2);
        }
        event.gc.drawText(text, event.x + TEXT_MARGIN, event.y + yOffset, true);
    }
});

要約すると、おそらく私は何か間違ったことをしています、IColourProviderそしてそれはとても簡単ですか?Tableまたは、またはTableViewerコンポーネント内にバグがあります。RCP 3.6.1をダウンロードして最新にアップグレードしましたが、同じ症状があります。

いくつかの助けをいただければ幸いです:-)

4

0 に答える 0