2

ブラックベリーのポップアップ画面に白枠をつけたいです。このコードを使用して境界線を追加します

Popup x = new Popup();
Border borderFocus = BorderFactory.createRoundedBorder(new XYEdges(10, 10, 10, 10), 0xffffff, Border.STYLE_SOLID);
x.getDelegate().setBorder(borderFocus);

///////////////////クラスのポップアップ////////////////////

public class Popup extends PopupScreen {

    public Popup() {
        super(new VerticalFieldManager(), Field.FOCUSABLE);

        HorizontalFieldManager hfm = new HorizontalFieldManager(
                Field.USE_ALL_WIDTH | FIELD_VCENTER);
        HorizontalFieldManager hfmBtn = new HorizontalFieldManager(
                Field.USE_ALL_WIDTH | FIELD_VCENTER | FIELD_HCENTER);


        LabelField title_screen = new LabelField("ddd");
        title_screen.setPadding(11, 5, 0, 0);
        hfm.add(title_screen);


        add(hfm);
        add(new SeparatorField());

        add(new LabelField(""));
        final LabelField labelVersion = new LabelField("ffffffffffffff");

        ButtonField btn_cancel = new ButtonField(
                "cancel");


        ButtonField btn_ok = new ButtonField("Yes");

        btn_ok.setPadding(0, 0, 0, 60);
        add(labelVersion);

        hfmBtn.add(btn_cancel);
        hfmBtn.add(btn_ok);
        add(new LabelField(""));
        add(hfmBtn);

    }

    public void sublayout(int width, int height){

        super.sublayout(width,height);

        setPosition(35,65);

    }
    public boolean onClose() {
        UiApplication.getUiApplication().popScreen();

        return true;

    }

しかし、私は境界線をポップアップに入れますが、ポップアップのウィンドウには白い境界線はありません。

ここに画像の説明を入力

4

2 に答える 2

2

これが問題を解決する最も簡単な方法かどうかはわかりませんが、私にとってはうまくいきます。

基本的に、 のデフォルトの境界線がPopupScreen問題を引き起こしています。コードを次のように変更した場合でも:

x.getDelegate().setBorder(borderFocus);

x.setBorder(borderFocus);

正しく見えません (丸い境界線の外側に長方形のフレームがあります)。

だから、私が基本的にやったことはこれです:

  1. デフォルトのPopupScreen境界線と背景を完全にクリア/透明にします。
  2. paintBackground(Graphics)クラスのメソッドをオーバーライドし、Popup単色の背景を手動で描画してから、角の丸い白い境界線を手動で描画します。

Popupしたがって、これをクラスに追加します。

   public class Popup extends PopupScreen {

      protected void paintBackground(Graphics g) {
         int oldColor = g.getColor();
         
         // we'll have to draw in the background, since we blanked it in
         //  the constructor
         g.setColor(Color.BLACK);
         int arcWidth = 20;
         g.fillRoundRect(0, 0, getWidth(), getHeight(), arcWidth , arcWidth);
         // and now, draw in the border manually
         g.setColor(Color.WHITE);
         g.drawRoundRect(0, 0, getWidth(), getHeight(), arcWidth , arcWidth);
         
         g.setColor(oldColor);
      }

      public Popup() {
         super(new VerticalFieldManager(), Field.FOCUSABLE);

         // make the screen's default border/background completely transparent
         setBackground(BackgroundFactory.createSolidTransparentBackground(Color.BLACK, 0));
         setBorder(BorderFactory.createRoundedBorder(new XYEdges(), Border.STYLE_TRANSPARENT));
         // use some padding to compensate for getting rid of the screen's default border
         int pad = 10
         setPadding(pad, pad, pad, pad);

         /** The rest of the constructor is as you originally had it */

次に、これらの行を削除できます。

Border borderFocus = BorderFactory.createRoundedBorder(new XYEdges(10, 10, 10, 10), 0xffffff, Border.STYLE_SOLID);
x.getDelegate().setBorder(borderFocus);

paintBackground()これは、現在メソッドで手動で行われているためです。

結果

ここに画像の説明を入力

于 2013-04-30T09:54:34.120 に答える