ContextMenu (Popup) always on - javafx-2

I have a problem with a Context menu in JavaFx 2:it never disappers when I left click on the graph of the JFXPanel
Does anybody knows how to solve this problem?
Thanks
Here is my code
final ContextMenu cm = new ContextMenu();
MenuItem chartItem1 = new MenuItem("Chart Settings");
cm.getItems().add(chartItem1);
getScene().setOnMouseReleased(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent mouseEvent) {
if(cm.isShowing()){
cm.hide();
}
if(mouseEvent.getButton() == MouseButton.SECONDARY)
{
cm.show(getScene().getRoot(), mouseEvent.getScreenX(), mouseEvent.getScreenY());
}
}
});
chartItem1.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent t) {
dialogs.ChartFormat cs = new dialogs.ChartFormat(null, true);
cs.setLocationRelativeTo(null);
cs.setVisible(true);
}
});

Reproduced the described behavior. Don't know the reason but you can use ContextMenu#hide():
final ContextMenu cm = new ContextMenu();
MenuItem menuItem = new MenuItem("Item 1");
menuItem.addEventHandler(EventType.ROOT, new EventHandler<Event>() {
#Override
public void handle(Event t) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
JPanel messagePane = new JPanel();
messagePane.add(new JLabel("label"));
JDialog jDialog = new JDialog();
jDialog.getContentPane().add(messagePane);
jDialog.pack();
jDialog.setVisible(true);
}
});
}
});
cm.getItems().add(menuItem);
scene.setOnMouseReleased(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent mouseEvent) {
// if(cm.isShowing())
cm.hide();
if (mouseEvent.getButton() == MouseButton.SECONDARY) {
cm.show(lineChart, mouseEvent.getScreenX(), mouseEvent.getScreenY());
}
}
});
Also you can check out these links:
http://pixelduke.wordpress.com/2011/12/11/popupmenu-in-javafx/
http://javafx-jira.kenai.com/browse/RT-17853
http://javafx-jira.kenai.com/browse/RT-14899
Adding sample code to your question would be more descriptive.

Related

I want to know how to randomly display images in gridview through SwipeRefreshLayout

SwipeRefreshLayout refreshLayout = findViewById(R.id.refresh_grid);
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
getImages();
refreshLayout.setRefreshing(false);
}
});
getImages();
}
I want to know how to randomly display images in gridview through SwipeRefreshLayout
I want a UI like the site https://www.pinterest.com
I want to show random images on refresh to show a lot of images, can you tell me how?
thank you in advance
Below is the full code.
public class MainActivity extends AppCompatActivity {
private List<String> mImagesLinks = new ArrayList<>();
private GridView mGridView;
FloatingActionButton option_01;
FloatingActionButton option_02;
FloatingActionButton option_03;
FloatingActionButton option_04;
static final int PERMISSIONS_REQUEST = 0x0000001;
//종료팝업 전면광고 추가
private static final String TAG = "ted";
TedAdmobDialog nativeTedAdmobDialog;
int nCurrentPermission = 0;
private AdView mAdView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, getString(R.string.admob_app_id));
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
checkPermission();
mGridView = findViewById(R.id.grid_view);
mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
startActivity(new Intent(MainActivity.this, ImageActivity.class)
.putExtra("Link", mImagesLinks.get(i)));
}
});
option_01 = findViewById(R.id.option_01);
option_01.setOnClickListener(v -> {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName()));
startActivity(intent);
});
option_02 = findViewById(R.id.option_02);
option_02.setOnClickListener(v -> {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/developer?id=Project+J+Lab"));
startActivity(intent);
});
option_03 = findViewById(R.id.option_03);
option_03.setOnClickListener(v -> {
Intent myintent = new Intent(Intent.ACTION_SEND);
myintent.setType("text/plan");
String shereBoday = "Your Boday Here";
String shereSub = "\"http://play.google.com/store/apps/details?id=" + getPackageName();
myintent.putExtra(Intent.EXTRA_SUBJECT, shereBoday);
myintent.putExtra(Intent.EXTRA_TEXT, shereSub);
startActivity(Intent.createChooser(myintent, "shere Using"));
});
option_04 = findViewById(R.id.option_04);
option_04.setOnClickListener(v -> {
Intent email = new Intent(Intent.ACTION_SEND);
email.setType("plain/text");
String[] address = {"dhsthdwjd1#gmail.com"};
email.putExtra(Intent.EXTRA_EMAIL, address);
email.putExtra(Intent.EXTRA_SUBJECT, getPackageName());
email.putExtra(Intent.EXTRA_TEXT, "text");
startActivity(email);
});
SwipeRefreshLayout refreshLayout = findViewById(R.id.refresh_grid);
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
getImages();
refreshLayout.setRefreshing(false);
}
});
getImages();
}
private void getImages() {
Call<List<String>> imagesResponse = NetworkUtils.getInterface().loadImages();
imagesResponse.enqueue(new Callback<List<String>>() {
#Override
public void onResponse(Call<List<String>> call, Response<List<String>> response) {
if (response.isSuccessful()) {
mImagesLinks = response.body();
ImagesAdapter imagesAdapter = new ImagesAdapter(MainActivity.this, mImagesLinks);
mGridView.setAdapter(imagesAdapter);
imagesAdapter.notifyDataSetChanged();
} else {
Toast.makeText(MainActivity.this, R.string.error_response, Toast.LENGTH_SHORT).show();
}
}
#Override
public void onFailure(Call<List<String>> call, Throwable t) {
Toast.makeText(MainActivity.this, t.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
});
}
#Override
public void onBackPressed() {
//종료팝업 전면광고 추가
nativeTedAdmobDialog = new TedAdmobDialog.Builder(MainActivity.this, TedAdmobDialog.AdType.NATIVE, getString(R.string.banner_ad_unit_id_native))
.setOnBackPressListener(new OnBackPressListener() {
#Override
public void onReviewClick() {
}
#Override
public void onFinish() {
finish();
}
#Override
public void onAdShow() {
log("onAdShow");
nativeTedAdmobDialog.loadNative();
}
})
.create();
nativeTedAdmobDialog.show();
}
//종료팝업 전면광고 추가
private void log(String text) {
Log.d(TAG, text);
}
private void checkPermission() {
PermissionListener permissionlistener = new PermissionListener() {
#Override
public void onPermissionGranted() {
}
#Override
public void onPermissionDenied(List<String> deniedPermissions) {
}
};
TedPermission.with(this)
.setPermissionListener(permissionlistener)
.setPermissions(
Manifest.permission.INTERNET,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.SET_WALLPAPER,
Manifest.permission.READ_CONTACTS)
.check();
}
}
Just use Collections.shuffle(list); in your getImages() function.
Refer this for more information : https://www.geeksforgeeks.org/shuffle-or-randomize-a-list-in-java/

I want to change my WebView content from a HTML file using thread in javafx

Here is my code. I am using scene builder. The code is not working.For first time it loads the hello1.html but in thread the hello2.html does not load.
public class TwavlController implements Initializable {
/**
* Initializes the controller class.
*/
#FXML public WebView webPane;
private Service<Void> back_thread;
private WebEngine engine;
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
engine = webPane.getEngine();
final String html_file = "hello1.html"; //HTML file to view in web view
URL urlHello = getClass().getResource(html_file);
engine.load(urlHello.toExternalForm());
run();
}
private File last_update,current;
public void run(){
back_thread = new Service<Void>() {
#Override
protected Task<Void> createTask() {
return new Task<Void>() {
#Override
protected Void call() throws Exception {
updateMessage("hello2.html");
return null;
}
};
}
};
engine.userAgentProperty().bind(back_thread.messageProperty());
back_thread.restart();
}
}
I'm not really clear what you're trying to do here, but I think maybe you are looking for
public void run(){
back_thread = new Service<Void>() {
#Override
protected Task<Void> createTask() {
return new Task<Void>() {
#Override
protected Void call() throws Exception {
Platform.runLater(() ->
engine.load(getClass().getResource("hello2.html").toExternalForm()));
return null;
}
};
}
};
back_thread.restart();
}

JavaFX is locking the app when after ActionEvent is done

I am building a menu (file, view, help, etc.). For ex. in File you have upload and exit (both working fine). In help I have some topics: ACF, ARIMA, HoltWinter, the idea is when you chose one of these a text to be displayed in a GridPane. The problem is when you chose one, it displays its text, but it also locks the whole app and you can do nothing, except close the app.
This is a file chooser and it's working just fine:
MenuItem upload = new MenuItem("Upload");
upload.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Resource File");
fileChooser.showOpenDialog(primaryStage);
}
});
And here is an event, which is blocking the app:
MenuItem acfH = new MenuItem("ACF");
acfH.setOnAction(new EventHandler<ActionEvent>(){
public void handle(ActionEvent event){
fr.md.pack.TextClass.acfText.setFill(Color.FIREBRICK);
fr.md.pack.TextClass.acfText.setText(fr.md.pack.StringClass.aboutACF);
grid.add(fr.md.pack.TextClass.acfText,1,10);
}
});
Any suggestions how to solve the issue?
Thanks in advance.
Here is the whole code:
public class MD extends Application {
#Override
public void start(final Stage primaryStage) throws IOException {
primaryStage.setTitle("Crude oil price prediction");
primaryStage.getIcons().add(new Image("file:resources/images/DukeWithHelmet.png"));
final GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));
Group root = new Group();
MenuBar menuBar = new MenuBar();
Scene scene = new Scene(root, 500,500, Color.WHITE);
scene.getStylesheets().add(this.getClass().getResource("style.css")
.toExternalForm());
primaryStage.setTitle("Crude oil price predicition");
menuBar.prefWidthProperty().bind(primaryStage.widthProperty());
Menu file = new Menu("File2");
MenuItem upload = new MenuItem("Upload");
upload.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Resource File");
fileChooser.showOpenDialog(primaryStage);
}
});
MenuItem exit = new MenuItem("Exit");
exit.setMnemonicParsing(true);
exit.setAccelerator(new KeyCodeCombination(KeyCode.X,KeyCombination.CONTROL_DOWN));
exit.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
Platform.exit();
}
});
Menu test = new Menu("Test");
MenuItem arima = new MenuItem ("ARIMA");
arima.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
}
});
MenuItem acf = new MenuItem ("ACF");
acf.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
}
});
MenuItem pacf = new MenuItem ("PACF");
pacf.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
}
});
MenuItem hw = new MenuItem ("HoltWinters");
hw.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
}
});
Menu help = new Menu("Help");
MenuItem arimaH = new MenuItem ("ARIMA");
arimaH.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
fr.md.pack.TextClass.arimaText.setFill(Color.FIREBRICK);
fr.md.pack.TextClass.arimaText.setText(fr.md.pack.StringClass.aboutArima);
grid.add(fr.md.pack.TextClass.arimaText, 1, 10);
}
});
MenuItem acfH = new MenuItem("ACF");
acfH.setOnAction(new EventHandler<ActionEvent>(){
public void handle(ActionEvent event){
fr.md.pack.TextClass.acfText.setFill(Color.FIREBRICK);
fr.md.pack.TextClass.acfText.setText(fr.md.pack.StringClass.aboutACF);
grid.add(fr.md.pack.TextClass.acfText,1,10);
}
});
MenuItem pacfH = new MenuItem ("PACF");
pacfH.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
fr.md.pack.TextClass.pacfText.setFill(Color.FIREBRICK);
fr.md.pack.TextClass.pacfText.setText(fr.md.pack.StringClass.aboutPACF);
grid.add(fr.md.pack.TextClass.pacfText, 1, 10);
}
});
MenuItem hwH = new MenuItem ("HoltWinters");
hwH.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
fr.md.pack.TextClass.hwText.setFill(Color.FIREBRICK);
fr.md.pack.TextClass.hwText.setText(fr.md.pack.StringClass.aboutHW);
grid.add(fr.md.pack.TextClass.hwText, 1, 10);
}
});
Menu about = new Menu("About");
MenuItem thisS = new MenuItem ("About this software");
thisS.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
fr.md.pack.TextClass.textRef.setFill(Color.FIREBRICK);
fr.md.pack.TextClass.aboutSoft.setText(fr.md.pack.StringClass.aboutSofttext);
grid.add(fr.md.pack.TextClass.aboutSoft, 1, 40);
}
});
MenuItem R = new MenuItem ("About R");
R.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
fr.md.pack.TextClass.textRef.setFill(Color.FIREBRICK);
fr.md.pack.TextClass.aboutR.setText(fr.md.pack.StringClass.aboutRtext);
grid.add(fr.md.pack.TextClass.aboutR, 1, 40);
}
});
MenuItem RServe = new MenuItem ("About RServe");
RServe.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
fr.md.pack.TextClass.textRef.setFill(Color.FIREBRICK);
fr.md.pack.TextClass.textRef.setText(fr.md.pack.StringClass.aboutText);
grid.add(fr.md.pack.TextClass.textRef, 1, 40);
}
});
file.getItems().addAll(upload,exit);
test.getItems().addAll(arima,acf,pacf,hw);
help.getItems().addAll(arimaH,acfH,pacfH,hwH);
about.getItems().addAll(thisS, R, RServe);
menuBar.getMenus().addAll(file,test,help,about);
root.getChildren().addAll(menuBar,grid);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
The classes used are just containing the strings to display:
package fr.md.pack;
public class StringClass {
final static String aboutText = "Малко информация за RServe.";
final static String aboutRtext = "Малко инфо за Р";
final static String aboutSofttext = "Малко инфо за софта";
final static String aboutArima = "Малко инфо за ARIMA";
final static String aboutACF = "Малко инфо за ACF";
final static String aboutPACF = "Малко инфо за PACF";
final static String aboutHW = "Малко инфо за Holt Winters";
}
Well, I just installed Java 8 and surprise....everything is working just fine. I used till now Java 1.7 update 45 and it was locking my application as soon as I try to use the Action event. With Java 8 it's working but not without some bugs....

How to show context menu in FlowPane body

I have a FlowPane which use used as stage for many BorderPane components. I created Context menu for the BorderPane components. I want to add second context menu also for the FlowPane but it turns out that I now have two context menus when I click on BorderPane. I need a way to exclude the second context menu from the BorderPane.
FlowPane flow;
public ScrollPane infrastructurePane()
{
flow = new FlowPane();
flow.setPadding(new Insets(5, 5, 5, 5));
flow.setVgap(15);
flow.setHgap(15);
flow.setAlignment(Pos.CENTER);
ScrollPane scroll = new ScrollPane();
scroll.setStyle("-fx-background-color:transparent;");
Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
scroll.setPrefSize(primaryScreenBounds.getWidth(), primaryScreenBounds.getHeight());
scroll.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); // Horizontal scroll bar
scroll.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); // Vertical scroll bar
scroll.setContent(flow);
scroll.viewportBoundsProperty().addListener(new ChangeListener<Bounds>()
{
#Override
public void changed(ObservableValue<? extends Bounds> ov, Bounds oldBounds, Bounds bounds)
{
flow.setPrefWidth(bounds.getWidth());
flow.setPrefHeight(bounds.getHeight());
}
});
//flow.setPrefWrapLength(170); // preferred width allows for two columns
flow.setStyle("-fx-background-color: white;");
for (int i = 0; i < 28; i++)
{
flow.getChildren().add(generatePanel(flow));
}
scroll = makeTabContextMenu(scroll);
String cssURL = "/com/dx57dc/css/ButtonsDemo.css";
String css = this.getClass().getResource(cssURL).toExternalForm();
flow.getStylesheets().add(css);
return scroll;
}
public BorderPane generatePanel(FlowPane flow)
{
HBox thb = new HBox();
thb.setPadding(new Insets(10, 10, 10, 10));
thb.setStyle("-fx-background-color: #006699;");
HBox bhb = new HBox();
bhb.setPadding(new Insets(10, 10, 10, 10));
bhb.setStyle("-fx-background-color: #B0B0B0;");
DropShadow ds = new DropShadow();
ds.setOffsetY(3.0);
ds.setOffsetX(3.0);
ds.setColor(Color.GRAY);
BorderPane bp = new BorderPane();
bp.setEffect(ds);
bp.setCache(true);
bp.setPrefSize(320, 180);
bp.setMaxSize(320, 180);
bp.setId("app");
bp.setStyle("-fx-background-color: linear-gradient(to bottom, #f2f2f2, #d4d4d4);"
+ " -fx-border: 2px solid; -fx-border-color: white;");
bp.setTop(thb);
bp.setBottom(bhb);
ScrollPane sp = new ScrollPane();
bp = panelContextMenu(bp);
bp = mouseOver(bp);
return bp;
}
public BorderPane mouseOver(final BorderPane bp)
{
bp.setOnMouseEntered(new EventHandler<MouseEvent>()
{
#Override
public void handle(MouseEvent t)
{
bp.setStyle("-fx-border: 2px solid; -fx-border-color: black;");
}
});
bp.setOnMouseExited(new EventHandler<MouseEvent>()
{
#Override
public void handle(MouseEvent t)
{
bp.setStyle("-fx-border: 2px solid; -fx-border-color: white;");
}
});
bp.setOnMouseClicked(new EventHandler<MouseEvent>()
{
#Override
public void handle(MouseEvent me)
{
if (me.getButton().equals(MouseButton.PRIMARY) && me.getClickCount() % 1 == 0)
{
bp.setPrefSize(480, 280);
bp.setMaxSize(480, 280);
}
if (me.getButton().equals(MouseButton.PRIMARY) && me.getClickCount() % 2 == 0)
{
bp.setPrefSize(320, 180);
bp.setMaxSize(320, 180);
}
}
});
return bp;
}
private ScrollPane makeTabContextMenu(ScrollPane scroll)
{
ContextMenu contextMenu = new ContextMenu();
MenuItem item1 = new MenuItem("New");
item1.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent e)
{
System.out.println("New");
flow.getChildren().add(generatePanel(flow));
}
});
// Rename
MenuItem rename = new MenuItem("Rename");
final TextField textField = new TextField();
rename.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent e)
{
System.out.println("Rename");
//textField.setText(label.getText());
//tab.setGraphic(textField);
textField.selectAll();
textField.requestFocus();
}
});
textField.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent event)
{
//label.setText(textField.getText());
//tab.setGraphic(label);
}
});
textField.focusedProperty().addListener(new ChangeListener<Boolean>()
{
#Override
public void changed(ObservableValue<? extends Boolean> observable,
Boolean oldValue, Boolean newValue)
{
if (!newValue)
{
//label.setText(textField.getText());
//tab.setGraphic(label);
}
}
});
// Orientation
Menu tabOrientation = new Menu("Orientation");
// Orientation sub menu - Top, Left, Right, Bottom
MenuItem tabOrientationSubTop = new MenuItem("Top");
tabOrientationSubTop.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent e)
{
//tabPane.setSide(Side.TOP);
}
});
MenuItem tabOrientationSubLeft = new MenuItem("Left");
tabOrientationSubLeft.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent e)
{
//tabPane.setSide(Side.LEFT);
}
});
MenuItem tabOrientationSubRight = new MenuItem("Right");
tabOrientationSubRight.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent e)
{
//tabPane.setSide(Side.RIGHT);
}
});
MenuItem tabOrientationSubBottom = new MenuItem("Bottom");
tabOrientationSubBottom.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent e)
{
//tabPane.setSide(Side.BOTTOM);
}
});
tabOrientation.getItems().addAll(tabOrientationSubTop, tabOrientationSubLeft, tabOrientationSubRight, tabOrientationSubBottom);
MenuItem item3 = new MenuItem("Close Tab");
item3.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent e)
{
System.out.println("Close Tab");
// Close the Tab and remove it from the TabPane
//tabPane.getTabs().remove(tab);
// If there are no tabs into the TabPane fill all empty space by resizing the near components
// if (tabPane.getTabs().size() == 0)
// {
// ActionTabs.getMainPane().setManaged(false); // Exclude the panel to fill the empty space
// }
}
});
MenuItem item4 = new MenuItem("Close All Panels");
item4.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent e)
{
System.out.println("Close All Panels");
flow.getChildren().clear();
}
});
contextMenu.getItems().addAll(item1, rename, tabOrientation, item3, item4);
scroll.setContextMenu(contextMenu);
return scroll;
}
public BorderPane panelContextMenu(final BorderPane bp)
{
final ContextMenu contextMenu = new ContextMenu();
MenuItem item1 = new MenuItem("About");
item1.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent e)
{
System.out.println("About");
}
});
MenuItem item2 = new MenuItem("Preferences");
item2.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent e)
{
System.out.println("Preferences");
}
});
MenuItem item3 = new MenuItem("Close");
item3.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent e)
{
flow.getChildren().remove(bp);
}
});
contextMenu.getItems().addAll(item1, item2, item3);
bp.setOnContextMenuRequested(new EventHandler<ContextMenuEvent>()
{
#Override
public void handle(ContextMenuEvent event)
{
contextMenu.show(bp, event.getScreenX(), event.getScreenY());
}
});
bp.addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>()
{
#Override
public void handle(MouseEvent event)
{
contextMenu.hide();
}
});
return bp;
}
Is there a way to show makeTabContextMenu() only visible for the FlowPane body?
Have you tried to set the event consumed?
#Override
public void handle(MouseEvent t)
{
...
t.consume()
...
}

How to work with LWUIT TABs click events

UPDATE:
My Requirement is to display two Rss files as Tabs on my LWUIT Form
Initially by default first Rss file titles and images should be displayed on first tab
if an end user click on second tab,we should be able to load the second rss file titles and images
I am able to load first Rss File titles,but i am not able to load the second tab if i click on it
How to capture the click event for LWUIT Tab?
Here my code which is not working:
String topNewsurl="TopNews.rss";
String topStoryurl="TopStory.rss";
public class XMLMidlet extends MIDlet{
public void startApp() {
Display.init(this);
Process p;
try {
p = new Process(this);
p.process();
} catch (IOException ex) {
ex.printStackTrace();
}
}
public class Process extends Form {
Process(XMLMidlet midlet) throws IOException {
this.midlet=midlet;
topnews = new Vector();
topstory = new Vector();
tabs = new Tabs();
form1 = new Form();
form2=new Form();
form1.setLayout(new BorderLayout());
form1.setScrollable(false);
image = Image.createImage("/res/Tone.jpg");
Label icon = new Label(image);
form1.setTitleComponent(icon);
form2.setTitleComponent(icon);
form1.setTransitionInAnimator(Transition3D.createRotation(250, true));
try {
newsList = new List(topnews);
newsList.setScrollVisible(false);
newsList.setRenderer(new NewsListCellRenderer());
myNewsList = new List(topstory);
myNewsList.setScrollVisible(false);
myNewsList.setRenderer(new NewsListCellRenderer());
tabs.addTab("Topstory", newsList);
tabs.addTab("TopNews", myNewsList);
tabs.setChangeTabOnFocus(true);
form1.addComponent(BorderLayout.CENTER, tabs);
}
try{
String url = "http:topnews-20.rss";
form1.show();
ParseThread myThread = new ParseThread(this);
myThread.getXMLFeed(url);
} catch (Exception e) {
e.printStackTrace();
}
}
public void addNews(News newsItem) {
//log.debug("addnews");
//System.out.println("addNews");
topnews.addElement(newsItem);
newsList.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
List source = (List) ae.getSource();
News selectedNewsItem = (News) source.getSelectedItem();
if (selectedNewsItem != null) {
displayCompleteNewsScreen(selectedNewsItem);
}
}
});
form1.show();
}
public void keyReleased(int keyCode) {
System.out.println("str");
Component p=this.getFocused();
String str= p.getClass().getName();
if(str.toLowerCase().indexOf("radiobutton")!=-1){
process();
}
From the very vague question it seems you want to capture key presses on a LWUIT Form.
jobsForm.addGameKeyListener(Display.GAME_FIRE,
new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//do something here
}
});
jobsForm.addPointerPressedListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
pointer_click = true;
}
});
jobsForm.addPointerReleasedListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (pointer_click) {
//
}
pointer_click = false;
}
});
jobsForm.addPointerDraggedListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//System.out.println("POINTER DRAGGED");
pointer_click = false;
}
});

Resources