2016-03-06 42 views
1

將組件設置爲容器中的引導組件時,將永遠不調用其longPointerPress()方法。永遠不會在引導組件上調用longPointerPress()

請看下面的例子:

final Button lead = new Button("Lead") { 
    @Override 
    public void longPointerPress(int x, int y) { 
     super.longPointerPress(x, y); 
     // Never invoked!!! 
     Dialog.show("", "Long pointer press at (" + x + "," + y + ")", "OK", null); 
    }}; 

// -------------------------------- 
// | Label | Lead | Another label | 
// -------------------------------- 
final Container c = BoxLayout.encloseX(new Label("Label"), lead, new Label("Another label")); 
c.setLeadComponent(lead); 

longPointerPress()是永遠不會被調用。但是,如果我設置c.setLeadComponent(null),則會調用長按。但是,我忽略了主要部分的概念。

這是一個錯誤?如果沒有,我怎麼才能意識到我想要做什麼?

回答

1

我想你應該嘗試這種方式

按鈕鉛=新的Button ....

lead.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (event.isLongEvent()) { //do long click event stuff }else{ //do normal click event stuff or blank if nothing to do } }

乾杯。

+0

感謝您的建議。不過,我想我早些時候嘗試過,並沒有奏效。 – sidiabale

0

這不是一個修復的bug。這工作:

Form hi = new Form("LongPress", new BoxLayout(BoxLayout.Y_AXIS)); 
hi.add(new MultiButton("Long Press") { 
    @Override 
    public void longPointerPress(int x, int y) { 
     System.out.println("Long press"); 
    } 
}); 

長指針按Container領導調用。

+0

1.爲什麼這被認爲是一個修復?我希望一旦有一個主要組成部分,它也會抓住長時間的壓力。 – sidiabale

+0

2.您提出的解決方案適用於MultiButtons,但MultiButton不夠用/使用的情況如何呢? PS:我畫的例子是一個簡化的例子。我有一個更復雜的UI,不適合MultiButton約束。 – sidiabale

+0

它適用於每個主要組件。只需重寫父容器中的longPress而不是組件本身。 –

相關問題