setBezelStyle not working on SWT NSButton - java - java

I'm creating an SWT (ported Mac OSX version) application. I am trying to set a specific button to have the bezel style of "inline". Here is what I want my button to look like on mac.
(screenshotted in storyboard view in xcode)
The code I am using to try to get this inline button:
// created button named "inlineButton" and applied layout to it.
// here is where I set the bezel style and text.
NSButton nsInlineButton = (NSButton) inlineButton.view;
nsSaveButton.setBezelStyle(15); // NSBezelStyleInline is enum 15 for cocoa
this.inlineButton.setText("Inline Button");
And the result:
(screenshotted from my java program)
I have also tried to redraw and relayout the shell and a variety of other methods with no avail.
Is this a bug or am I doing something wrong?

Solved. I just needed to add the SWT style of "FLAT"
this.inlineButton = new Button(this, SWT.FLAT);
NSButton inlineButton = (NSButton) inlineButton.view;
inlineButton.setBezelStyle(15);

Related

Is there any alternative for setWindowAnimations(Android) in Harmony OS?

I am developing a Harmony application and I want to animate the Dialog window
this code is from android and this type of animation I want to add
Window dialogWindow = dialog.getWindow();
dialogWindow.setWindowAnimations(R.style.CustomDialogAnimation);
// properties that needs to be attached to Dialog window
duration="75"
fromXScale="0"
fromYScale="0"
toXScale="1"
toYScale="1"
I didn't find anything matching documentation like setWindowAnimations.
I tried writing this code but hit a dead end after getting the dialog window. How to add animation properties to this dialog window.
CommonDialog commonDialog = new CommonDialog(getContext);
Window dialogWindow = commonDialog.getWindow();
Is there any other way to code this?
According to the team, HarmonyOS does not currently support to add animation properties to dialog window. Please stay tuned on HarmonyOS official websites.

Winium - how to access tool bar item if that bar doesn't have child

I am using Winium + Java for automation testing of Windows application, and trying to access tool bar menu.
When I tried to detect elements using UI Automation Verify, I couldn't see child elements under tool bar element like below screenshot.
enter image description here
But my tool bar definitely has sub menu items like screenshot and I need to access them.
enter image description here
I tried below java code, but it didn't work
WebElement el = driver.findElement(By.id('59398'));
el.click();
WebElement child = el.findElement(By.name('Start'));
child.click();
when I tried
driver.findElement(By.name"Start').click();
it clicked my windows start menu, not my application's menu.
Is there any way to access items under this tool bar?
You can try use another UI Inspector
eg. UI SPY or Inspector.exe
Probably your ID is not a AutomationID (process id?)
You should find a main window (parent of your app) (Example for calc) and get a parameter like AutomationId, ClassName or Name
I see this is MFC application, and this is an app side MFC library problem. If you hover mouse over toolbar button using Inspect.exe, the info is available but you can't reach this button from the hierarchy (the buttons have no parent somehow). Possible workaround involves combined Win32 API and UI Automation approach:
get button rectangle using Win32 API (but there is no text).
use ElementFromPoint method of UI Automation API and get actual texts to choose the right button.
P.S. My suggestion is applicable for Java + Winium in theory. But I can't estimate the complexity because I'm not a Java expert. So below is Python solution.
We have plans to implemented this mixed way in pywinauto. See issue #413. It contains Python code sample how to do that. We've had no chance to integrate it yet.
from ctypes.wintypes import tagPOINT
import pywinauto
app = pywinauto.Application().start(r'.\apps\MFC_samples\RebarTest.exe')
menu_bar = app.RebarTest.MenuBar.wrapper_object()
point = menu_bar.button(0).rectangle().mid_point()
point = menu_bar.client_to_screen(point)
elem = pywinauto.uia_defines.IUIA().iuia.ElementFromPoint(tagPOINT(point[0], point[1]))
element = pywinauto.uia_element_info.UIAElementInfo(elem)
print(element.name)

Display numbers on a tray icon with SWT

I would like to show some numbers on my tray icon indicating a number of events that happened to the user like what is done in this facebook notifications icons:
Do you think that it is possible ?
Thank you
You can do this using the TaskBar and TaskItem classes although it may not work on all platforms.
TaskBar taskBar = Display.getDefault().getSystemTaskBar();
// TODO may return null if not supported on the platform
// Get application item
TaskItem taskItem = taskBar.getItem(null);
if (taskItem != null)
taskItem.setOverlayText("your text");
Also try:
TaskItem taskItem = taskBar.getItem(shell);
where shell is your main application shell. The TaskItem JavaDoc suggests trying both methods of getting the TaskItem:
For better cross platform support, the application code should first
try to set this feature on the TaskItem for the main shell then on the
TaskItem for the application.

Setting width of controlsFX dialogs

I'm using controlsFX for dialogs and I can't figure out how to set the width. A lot of my messages only include the title, masthead and buttons. But the text in the buttons isn't fully display. For example:
Action deleteStuff = new DialogAction("Delete Stuff", ButtonBar.ButtonType.OTHER);
Action deleteMoreStuff = new DialogAction("Delete More Stuff", ButtonBar.ButtonType.OTHER);
Action response = Dialogs.create()
.owner(stage)
.title("Delete")
.masthead("This is a delete dialog")
.actions(deleteStuff,deleteMoreStuff,Dialog.ACTION_CANCEL)
.showConfirm();
And one of the buttons will show: "Delete Mo..."
And yes, I know I should be using the Alert class, but the project is for machines running older versions of Java. Thanks in advance.

displaying a Message using SWT

I am trying to a display message when i will push save button saying that the content got saved using SWT. Can anyone please help me.
Note: I am not using Jface, Shell, Display. I am using a Composite.
Actually, you are using a Display and a base Shell. But these are hidden behind your Eclipse RCP app. I'm guessing you are creating your message dialog in the createContents(Composite) method of a ViewPart, correct?
You can access the Display with Display.getCurrent() anywhere in your code, and you can get the active Shell with parent.getActiveShell().
If you don't want to use JFace, use the MessageBox widget from SWT.
MessageBox box = new MessageBox(parent.getActiveShell(), SWT.CANCEL | SWT.OK);
box.setText("Title");
box.setMessage("This will be the message");
box.open(); // Call this on button pressed. Returns SWT.OK or SWT.CANCEL
If you want specific features for the MessageBox, you can either ask me in a comment, or check out these 18 Java code examples.
Alternatively you can use as below
MessageBox box = new MessageBox(comp.getShell(), SWT.CANCEL | SWT.OK);
Where comp is Composite.

Categories

Resources