I have extended org.controlsfx.dialog.Dialog and added some TextField to it, which is supposed to act when ENTER button is pressed (if TextField has focus). However when I press ENTER, my dialog takes over of steering, and act like on OK button was pressed.
Is there any method which I can override in order to change this behavior (to intercept Enter action)?
Thanks in advance
I have received some workaround to this problem at ControlsFX mailing list which is good for me. To disable Dialog closing after Enter button is pressed in TextField we must consume event in EventHandler attached to this TextField
textField.addEventFilter(new EventHandler() {
public void handle(KeyEvent evt) {
.......
evt.consume();
}
});
For me works this:
dialog.getDialogPane().addEventHandler(KeyEvent.KEY_PRESSED, event -> {
if (event.getCode() == KeyCode.ENTER) {
event.consume();
}
});
Related
I have an Android application with a dialog and a few buttons inside.
I want to reuse the dialog for different purposes and looking for a way to call the button from a separate class and define an action event for it.
Creating a test class, I managed to define an action event for a button inside a form, but the same code does not work for a button inside a dialog, and I can't get my head around why it is not working for the dialog.
Below is what I already have. Any suggestions would be appreciated.
public Class One {
Test test = new Test();
test.testOne(); // this is working : button prints
test.testTwo(); // this is not working : button does not print
buttonTest = test.getTestButton();
buttonTest.setText("Hello World"); // not working for a button in a dialog
buttonTest.addActionListener(l-> { // prints when the button in a Form
System.out.println("try"); // does not print when the button is in a dialog
});
}
public class Test {
Dialog dialog = new Dialog();
Form form = new Form();
Button button;
public void testOne() {
button = new Button("Test");
form.add(button);
form.show();
}
public void testTwo() {
button = new Button("Testing");
dialog.add(button);
dialog.show();
}
public Button getTestButton () {
return button;
}
}
You add the action listener after showing the form and dialog. This isn't a problem for the form since the forms show method will continue. But a dialogs show() method will block.
Two solutions:
Move the listener binding higher in the code (before the show) that would be a problem since the button doesn't exist yet so you will need some refactoring.
Change the show() call on the dialog to showModless()
I have a DataWindow (MyWindow) with the OK Cancel and Apply buttons. Within this DataWindow is a View (MyView). For both MyWindow and MyView I have overridden GetViewModelType() like so:
protected override Type GetViewModelType()
{
return typeof(MyViewModel);
}
I also have MyViewModel registered with MyWindow via the UIVisualizerService:
_uiVisualizerService.Register(typeof(MyViewModel), typeof(MyWindow));
On MyViewModel I have overridden ViewModelBase.Save():
protected override bool Save()
{
if (HasErrors)
return false;
MyModel.SaveChanges();
return base.Save();
}
I use this to display MyWindow:
var myViewModel = TypeFactory.Default.CreateInstanceWithParametersAndAutoCompletion<MyViewModel>();
_uiVisualizerService.Show(myViewModel);
But when I click on the 'OK' Button of MyWindow, although the Save() method is called and base.Save() returns 'true', the Window is not closed.
If I open the MyWindow using,
new MyWindow().ShowDialog();
the 'OK' button works.
Am I missing something or doing something wrong? The Apply and Cancel Buttons work 100%
EDIT:
I just noticed something, using Show() does not close the window when OK is clicked (as said above) BUT ShowDialog() does.
Is this correct?
Issue was fixed by updating to Catel v4.0.
I would like to change the Icon of a menu item after its clicked. (I am talking about the action menu which deploys on the Action key press)
This is what I have so far:
#Override
public void onMenuItemSelected(final int menuItem) {
if (menuItem == MENU_ITEM_START) {
if(!Started){
Started=true;
**Intent intent = new Intent(Control.Intents.CONTROL_MENU_SHOW);
intent.putExtra(Control.Intents.EXTRA_MENU_ITEM_ID,MENU_ITEM_START);
intent.putExtra(Control.Intents.EXTRA_MENU_ITEM_ICON, ExtensionUtils.getUriString(mContext, R.drawable.menu_item_stop));
sendToHostApp(intent);**
mHandler.postDelayed(RunnableObject, 1000);
}
else{
Started=false;
mHandler.removeCallbacks(RunnableObject);
}
}
}
So, I added the bolded code (between ** and **), to start an intent to "change" the icon in the same way I create the menu the first time, however, that wont work.
Maybe wrong intent: CONTROL_MENU_SHOW?? That is the one I found in the Control Class when initializing the menu.
Any help is appreciated, thanks!!
Nope, there's no way to do it directly. The way you are doing it is the only way.
I want identify all mouse click event in PreTranslateMessage, but when I use WM_LBUTTONDOWN than WM_LBUTTONDBLCLK portion never called. Please tell me how can I identify all events separately.
This code will get the mouse click events in PreTranslateMessage
BOOL CSampleDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_LBUTTONDOWN)
{
//add ur customized code here...
return false;
}
return CDHtmlDialog::preTranslateMessage(pMsg);
}
I am using mfc CDialog. I need to show the close and minimize/maximize button, but they should not close or maximize the dialog. I have overriden OnClose method and kept the dialog open even if close button is clicked. But I am unable to block maximize and minimize of the dialog as there doesn't seem to be a OnMaximize method. Is there an alternative way?
You need to handle the WM_SYSCOMMAND message, watching for wParam == SC_MAXIMIZE.
If you catch the SC_MINIMIZE, you can do what you want and not pass it on to Windows.
msdn
Found this snippet here.
const int WM_SYSCOMMAND= 0x0112;
const int SC_MAXIMIZE= 0xF030;
protected override void WndProc(ref Message m)
{
if(m.Msg==WM_SYSCOMMAND)
{
if((int)m.WParam==SC_MAXIMIZE)
{
MessageBox.Show("Maximized!!");
return; // swallow the message
}
}
base.WndProc (ref m);
}
You can not show at all the minimise/maximise icons i your dialog. You can do that by going to Dialog properties (right vlick on your Dialog Contorol --> Properties), Select Styles pain and unselect 'Minimise Box', 'Maximise Box'.