I am trying to show an Alert with a long message, and it tends to get truncated at a word boundary.
I think it's only a Windows and Linux issue. I found some answers that propose this solution: alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);.
Or this one:
alert.getDialogPane().getChildren().stream().filter(node -> node instanceof Label).forEach(node -> ((Label)node).setMinHeight(Region.USE_PREF_SIZE));
However, I still have the same problem on my CentOS.
Alert alert = new Alert(AlertType.CONFIRMATION, Messages.AoiPanel_confirmation_message, ButtonType.YES, ButtonType.NO);
alert.setTitle("");
alert.initOwner(deleteButton.getScene().getWindow());
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alert.showAndWait();
This is what I mean by get truncated at a word boundary (sorry I can't share the image of the real application as my centOS is a secure OS and the application is private).
If it helps, I use win7 + java 1.8.0_102 and xubuntu + java 1.8.0_111 and the text is only truncated after 12 lines. But because the alert dialog doesn't seem to extend horizontally by default and most of the messages in my project are rather long, I also use...
alert.getDialogPane().setMinWidth(600);
... so I don't have that problem any more.
Related
I am using Eclipse 3.7.0 for plugin development and I am using Xtext 2.9.2. My editor preferences isn't working correctly.
On windows 7, 8, 10 this happens:
.
On 64 bit builds, I am not able to change editor font. Hitting the change button does nothing but change the mouse to the busy/sandclock for a second and then back again to normal.
The same 64 bit builds were tested on windows XP and everything works as it should.
On 32 bit builds, everything works as expected and the windows font picker dialog appears.
This is how I create the preference page:
#Override
protected void createFieldEditors() {
// Add show font preference
fontField = new FontFieldEditor(JFaceResources.TEXT_FONT, EDIT_EDITOR_FONT_LABEL, getFieldEditorParent());
addField(fontField);
fontField.setPreferenceStore(getPreferenceStore());
// initialize the font preference with the default resources font if not initialized
String defaultFont = getPreferenceStore().getDefaultString(JFaceResources.TEXT_FONT);
if(defaultFont.isEmpty()) {
font= JFaceResources.getTextFont();
if (font != null) {
FontData[] data= font.getFontData();
if (data != null && data.length > 0) {
PreferenceConverter.setDefault(getPreferenceStore(), JFaceResources.TEXT_FONT, data[0]);
}
}
}
}
The .log file is empty and has nothing that is beneficial.
While debugging, I went to org.eclipse.swt.widgets.FontDialog.java and found that this line always returns false without the dialog appearing. From what I understand this call should be blocking and will only return when the dialog is closed either by X, OK or Cancel buttons but it returns immediately with false.
/* Open the dialog */
boolean success = OS.ChooseFont (lpcf)
I also tried something as minimal as this example and same thing happens.
Months passed and I figured out what was causing the issue.
Basically we have a JNI layer which loads some dll that requires MSVCR90.dll. This requires embedding MSVCR90.dll manifest into eclipse.exe used for our RCP, this is done using mt.exe provided by Microsoft Visual Studio.
While building I accidentally didn't embed the MSVCR90.dll manifest, this resulted into the error during loading the dll which says that MSVCR90.dll is missing. I however noticed that the treeview styling looked correct.
This was also the answer to my other question Eclipse RCP Jface/SWT TreeViewer on Windows 10. The manifest also affected the UI look and feel treeviews and progressbars didn't look like the ones provided by the OS.
I have two questions regarding issue with FirefoxProfile(I've spent a lot of time digging in the Internet so finally I have to ask here).
PROBLEM NR 1: I have to deal with a Flash animation using Selenium WebDriver(Java) with Firefox. For this particular reason I cooperate with Sikuli and it works fine.
The problem is that from time to time my test fails due to the fact that Adobe Flash Player is not updated and firefox throws a warning about this situation.
I suppose that I have to change something in the profile but I was searching for exact preferences but any success.
QUESTION NR 1: Is this possible? If so what I have to change?
PROBLEM NR 2: I would like to take this opportunity and ask second question:
My second goal is to open PDF file after click on a link(currently a new system window appears with information what I want to do -open/save and so one). Okey- I can deal with saving a file with this main preference and few more:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
but when I want to use:
profile.setPrefernce("browser.helperApps.neverAsk.openFile", "application/pdf")
still this system window(with question about open/save) appears.
QUESTION NR 2: What I have to add to that line above to open a PDF file in a new browser window and preview it?
Thanks a lot in advance for any hints!
Update: anyone can help me with this?
First you have to wait till alert pops up as below (max 60 seconds),
new WebDriverWait(driver, 60)
.ignoring(NoAlertPresentException.class)
.until(ExpectedConditions.alertIsPresent());
After alert pop up, you can dismiss alert,
driver.switchTo().alert().dismiss();
I'm working on an Eclipse RCP project and need to let the user select some file.
For convenience, based on some conditions, the initial directory of the file choosing dialog should be set prior to opening it.
As I'm bound to Eclipse RCP / SWT, I am working with the org.eclipse.swt.widgets.FileDialog.
The documentation of this FileDialog points out to use the setFilterPath(String string)-method which should do exactly what I need (see documentation).
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
dialog.setFilterExtensions(new String [] {"*.html"});
dialog.setFilterPath("c:\\temp");
String result = dialog.open();
Unfortunately it is not working, at least not "every time".
I have currently no installation to check on it, but I'm quite sure that the feature would work totally fine on a Windows 200/XP/Vista machine.
I am working with a Windows 7 machine and I think I am suffering from the behaviour described here for lpstrInitialDir.
At least, this is exactly the behaviour I am facing: The path is good the first time I open the dialog, but the second time, the path is initially set to the last chosen path.
This seems to be convenient in most cases, but it is not in mine.
Can this be right?
If so, have I any chance on changing the behaviour according to my needs?
Thanks for any helping answer!
I ran into the same problem on Windows 10 and found a solution that seems to be working for me. A code snippet from the DirectoryDialog led to the right direction:
if (filterPath != null && filterPath.length() > 0) {
String path = filterPath.replace('/', '\\');
char[] buffer = new char[path.length() + 1];
path.getChars(0, path.length(), buffer, 0);
if (COM.SHCreateItemFromParsingName(buffer, 0, COM.IID_IShellItem, ppv) == OS.S_OK) {
IShellItem psi = new IShellItem(ppv[0]);
/*
* SetDefaultDirectory does not work if the dialog has
* persisted recently used folder. The fix is to clear the
* persisted data.
*/
fileDialog.ClearClientData();
fileDialog.SetDefaultFolder(psi);
psi.Release();
}
}
The FileDialog misses this statement 'fileDialog.ClearClientData()'. My solution is to execute the following code before setting the path and open the dialog:
long [] ppv = new long [1];
if (COM.CoCreateInstance(COM.CLSID_FileOpenDialog, 0, COM.CLSCTX_INPROC_SERVER, COM.IID_IFileOpenDialog, ppv) == OS.S_OK) {
IFileDialog fileDialog = new IFileDialog(ppv[0]);
fileDialog.ClearClientData();
fileDialog.Release();
}
Now you can set the filterpath without Windows messing things up.
I found a simple Solution for the Problem you described (I had the exact same Problem).
Just rearrange the your code like this:
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
dialog.setFilterPath("c:\\temp"); // This line is switched with the following line
dialog.setFilterExtensions(new String [] {"*.html"});
String result = dialog.open();
Somehow the Order of the methods called is relevant.
Are you using the same FileDialog object when you re-open it?
I ran a few quick tests and found that, if you re-set the filterPath, the dialog opens in the correct location.
If I open the same object again, it starts in the previously selected location.
I'm writing an application that runs in the System Tray and notifies the user (i.e. makes one of those bubbles pop up) when something happens. The only problem is that the notifications only seem to work on Windows 7, and not Windows XP.
I've tested it on 2 Windows 7 computers (they've both worked) and 4 Windows XP computers (none of them have worked). No notification bubble is shown, and (as far as I know) no exceptions are thrown and everything else works as it should. I've even tested it on a Mac, and it worked, but it wasn't too pretty.
Here is a sample of my code.
private static TrayIcon trayIcon;
...
trayIcon = new TrayIcon(trayImage.getImage());
...
if (!SystemTray.isSupported())
{
System.out.println("SystemTray is not supported");
return;
}
final PopupMenu popup = new PopupMenu();
final SystemTray tray = SystemTray.getSystemTray();
trayIcon.setToolTip("Widget Name Here [" + role + "]");
...
try
{
tray.add(trayIcon);
}
catch (AWTException e)
{
System.err.println("TrayIcon could not be added.");
return;
}
...
//Here's where it doesn't work on XP
trayIcon.displayMessage("Connection error",
"Could not connect to server, please check your internet/VPN "
+ "connection", TrayIcon.MessageType.ERROR);
Any help would be much appreciated.
UPDATE: Ok, I've just confirmed that it's not a problem with my program, but a problem with the XP installations I've been testing them on. I ran the TrayIconDemo.java program found here on an XP computer and none of the notifications worked. I'm starting to think there's nothing I can do to get it to work on one of these computers...
Okay, so I've finally found the solution to my problem. It turned out that the following key was set to 0 (false) by default on the installations I was testing on:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\EnableBalloonTips
To enable the notification bubbles, simply set the value to 1.
I have Windows XP and working on system tray application. I have just added displayMessage() and it works just fine for me. Try to simplify your application. I am sure it will work. The find a bug.
EDIT: you didn't mentioned JRE version System try required Java6
this should be comment, but this is restrict for chars lenght
maybe, there is another reason in case of when Java updates are distributed by some of administrations tool for AD or ZenWorks, then sometimes (on both win7/Xp) is needed un-install all java instalactions and install fresh JRE manually (but stable 1.6.022 my view), sw distibutions ends without error, but all (???) classes/methods/changes cames from Java6 weren't accesible, on partial (RowSorter etc...) test ends with error, and I never search for knows Bugs on MS, Novell ...
From within Java, I am opening an Excel file with the default file handler (MS Excel, in this case :-) ) using the method described in this stackoverflow question:
Desktop dt = Desktop.getDesktop();
dt.open(new File(filename));
However, the Excel program doesn't get the focus. Is there any easy way to do so?
Edit: There is a related stackoverflow question for C#, but I didn't find any similar Java method.
Edit 2: I've did some simple tests, and discovered that Excel starts and gets the focus whenever no instance of Excel is running. When Excel is already open en NOT minimized, the application doesn't get the focus. If instead the Excel Windows was minimized, the above code will trigger a maximization of the window and Excel getting the focus (or vice versa :-) ).
If you only care about Windows (implied in the question), you can change the way you invoke Excel: use "cmd start...".
I have been using this piece of code to launch Windows applications for some time now. Works every time. It relies on the file association in Windows to find the application. The launched application becomes the focused window on the desktop.
In your case, Excel should be associated with .xls, .csv and other typical extensions. If it is, Windows will launch Excel, passing your file to it.
Usage:
MyUtilClass.startApplication( "c:\\mydir\\myfile.csv", "my window title" );
file is the full path to the input file for Excel and title is the window title (the application may or may not take it - Excel changes the window title).
public static void startApplication( String file, String title )
{
try
{
Runtime.getRuntime().exec( new String[] { "cmd", "/c", "start", title, file } );
}
catch( Exception e )
{
System.out.println( e.getMessage() );
}
}
From a scala-program, which runs in the JVM too, I can open an application, and that get's the focus by default. (Tested with xUbuntu, which is a kind of Linux).
import java.awt.Desktop
val dt = Desktop.getDesktop ();
dt.open (new java.io.File ("euler166.svg"));
I can't say, whether this is specific for Linux, or maybe something else - however starting Inkscape in my example, excel in yours, may take a few seconds, while the user impatiently clicks in the javaprogram again, thereby claiming the cursor back. Did you check for that?
You could then change to the last application, at least on Linux and Windows with ALT-Tab aka Meta-Tab (again shown in scala code, which you can easily transform to javacode, I'm sure):
import java.awt.Robot
import java.awt.event._
val rob = new Robot ()
rob.keyPress (KeyEvent.VK_META)
rob.keyPress (KeyEvent.VK_TAB)
rob.keyRelease (KeyEvent.VK_TAB)
rob.keyRelease (KeyEvent.VK_META)
but unfortunately the unknown source off more trouble, also known as user, might do nothing, so switching would be the false thing to do. Maybe with a thread, which checks for a certain amount of time, whether the java-program has the focus, but it keeps a form of roulette, in an interactional environment, because the user may have a fast or slow machine, or change to a third application meanwhile, and so on. Maybe a hint before triggering the new app is the best you can do?