Random Image in Java Dialog Popup Boxes - java

Random images keep appearing in all of my my Java popup boxes: The "inKeep editor" should not be there... the 'inkeep editor' image is a file called 'icon' and is used for the apple dock.
String response = JOptionPane.showInputDialog(Home.toolbar, "Please confirm your password to make changes", "Confirm Password", JOptionPane.QUESTION_MESSAGE);
JOptionPane.showMessageDialog(Home.toolbar, "Wrong Password", "Verify Account", JOptionPane.ERROR_MESSAGE);
I'm setting this image as the dock icon (mac) but not for pop boxes (to my knowledge).
Application application = Application.getApplication();
Image image = Toolkit.getDefaultToolkit().getImage("src/resources/icon.png"); // Sets apple icon image
application.setDockIconImage(image);
Does anyone know how to get rid of these images in the dialogs? The big red (!) is intended but not the inKeep editor over it.

This is the expected behavior -- a feature. When you give your application an icon, it will display it on top of the default warning/error icons. This reinforces with the user that the dialog that just popped up is from your application and not another or the OS.
For example, here how it looks using the default Java app icon:
To add a custom icon, you can do something like this:
ImageIcon icon = new ImageIcon(...);
JOptionPane.showMessageDialog(null, "", "", JOptionPane.ERROR_MESSAGE, icon);

Related

Setting the icon for a MessageDialog causes issues

I'm trying to set an Icon for a Message Alert popup, and I'm using the methods I've found online. However, they're causing issues where the image:
Doesn't even get set as the icon
Is way too oversized
Placed in the JPanel
The screenshot below shows what I mean:
Screenshot of Issue
And my code doesn't seem to have any issues:
final ImageIcon iconF = new ImageIcon(LOGIN.class.getResource("/resources/offline.png"));
JOptionPane.showMessageDialog(null, "ERROR: Please check your username and password then try again.", "Login Failed", JOptionPane.ERROR_MESSAGE, iconF);
I don't understand what's causing this mess of an issue when this seems to be the "answer" to my own question.

Create jDialog Swing with a message of error with image

I'm new of Java and I want to do a jDialog that is opening when I push a button in the main JFrame and show a message of error in this way:
I can't put the image in another way in NetBeans? I create in the source package a directory with the image and a try much thing:
jDialog1.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
jDialog1.add(new JLabel(new ImageIcon(ImageIO.read(getClass().getResourceAsStream("/img/error_button.png")))));
jDialog1.pack();
jDialog1.setLocationByPlatform(true);
jDialog1.setVisible(true);
Is there a simple way to do this?
We can use an option pane for this. It includes its own icons according to the type of message (and look and feel).
Exception e = new Exception("Error!");
JOptionPane.showMessageDialog(f, e, e.getMessage(), JOptionPane.WARNING_MESSAGE);

How to display Messagebox with Retry option in JAVA?

Scenario:
Pickup some data from an Excel file.
Search for it in a Text file.
If the data is not found, display a popup message box with a 'Retry' option.
User opens the Excel file and changes the value.
Click the 'Retry' button.
The Line which threw the error earlier should get executed again.
I need to know, how to display a message box with a 'Retry' option, clicking on which shall execute the line of code again.
Just place the code that pops up the box in a loop and continue the loop if the retry button was clicked. The response code from the jOptionPane tells you what button was popped.
this will give you an option pane with 4 buttons java C++ VB COBOL
String[] choices = {"Java", "C++", "<acronym title="vBulletin">VB</acronym>", "COBOL"};
int response = JOptionPane.showOptionDialog(
null
, "Which is your favourite programming language?"
, "Language Poll"
, JOptionPane.YES_NO_OPTION
, JOptionPane.PLAIN_MESSAGE
, null
, choices
, "None of your business"
);

add badge to tray icon (java)

i have created a simple app in java to show a tray icon and from there show a list of JIRA issues that are assigned to me.
what i have at the moment is a tray icon that when you right click on it brungs up a popup message with the last 10 open issues assigned to me, when you click a menu item it directs you to the desired issue in your browser of choice.
What i would now like it to do is display a badge over the top of the tray icon that shows how many open issues i have. i have the code to find the number of issues but i cant for the life of me work out how to add the badge to the tray icon.
im using :
java.awt.MenuItem;
java.awt.PopupMenu;
java.awt.SystemTray;
java.awt.TrayIcon;
to create the tray icon and popup menu.
any help would be greatly appreciated
Thanks
Okay so i figured it out,
first i select the original icon:
BufferedImage im = ImageIO.read(Systray.class.getResource("icon.gif"));
then i use Graphics2D to draw ontop of the image:
Graphics2D g2 = im.createGraphics();
g2.setColor(Color.BLACK);
g2.drawString("10", 2, 10);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(im, "png", baos);
byte[] b = baos.toByteArray();
then i create a new image icon from the byte array:
ImageIcon imgTmp = new ImageIcon(b);
finally i set the tray icon:
_icon.setImage(imgTmp.getImage());
(_icon is an instance of TrayIcon)
i hope that this helps someone else and if you have a better solution id love to see it

Object not found error on OK button in the dialog box

In my application , by clicking the save button, the dialog prompts a message with OK button. While recording 'the OK button' got recorded and shows 'text_ok().click(atpoint(11,8));'. But during play back it shows me a 'Object not found' error.
Recently updated the RFT Version 8.2.2.1 after this only this issue is seen.
Can anyone say me how to solve this problem or any coding in java.
My regression is waiting due to this, your help is highly appreciable.
Thanks in Advance.
You have not mentioned what type of dialog window it is. But you can try the IWindow API of RFT to find active top window and perform the click as specifed below.
The Following code for eg can handle an alert dialog box in html by calling
handleDialogButton("Message from Webpage", "ok");
Or,to click on canel button on Notepad's Font dialog (Format>Font) by calling
handleDialogButton("font","cancel");
-------Sample code----
/*
* Activates the top window with the given caption and clicks on the child control(window) with the specified text
* #param caption- Caption of the Dialog window
* #param btnToClick- Text of the button(any other control) to click
*/
void handleDialogButton(String caption,String btnToClick)
{
IWindow[] windows = getTopWindows();
for(IWindow window: windows)
{
if(window.getText().equalsIgnoreCase(caption))
{
window.activate();
//window.close(); //we can just close it also n break.
IWindow[] children = window.getChildren(); // OR go thru the children to get the child
for(IWindow child:children)
{
if(child.getText().equalsIgnoreCase(btnToClick))
{
child.click();
break;
}
}
}
}
unregisterAll();
}
From the poing of Selenium Web driver API i recommend you do the following:
Alert alert = driver.switchTo().alert();
alert.accept();
Hope this works for you

Categories