Java Mac how to create an about window like finder's - java

I am programmi an application for mac and I would like to have an about window to show to the user some infos, like the one of Finder.
Actually I am using this code:
System.setProperty("apple.laf.useScreenMenuBar", "true");
// SET NAME IN THE MACMENUBAR
System.setProperty("com.apple.mrj.application.apple.menu.about.name", Constants.APP_NAME);
Application application = Application.getApplication();
Image image = Toolkit.getDefaultToolkit().getImage("res/logo.png");
application.setDockIconImage(image);
application.setAboutHandler(new AboutHandler() {
public void handleAbout(AboutEvent arg0) {
JOptionPane.showMessageDialog(null, "Some infos.");
}
});;
but the thing that I obtain is not what I want, because is a dialog box with the "logo.png" image on the left and the text on the right. And also a big awful "OK" button that you must press to close the window.
How can I make a simple about window like Finder's ?
Can you help me? I found many tutorial on the net, but all are using deprecated methods in Application class.
(sorry for my bad english, I am italian)

You have at least two options:
Create a JPanel (possibly your own subclass) and layout the components in it as you want. Then show it with JOptionPane.showMessageDialog() by passing it as the first argument, rather than passing null as you have.
Create a JDialog and layout the components yourself. Again, you may want to create a subclass of JDialog to do this.

Related

Login without multiple windows

I'm using Windows builder for create an application in Java. I create a frame with the login interface. What i want is that if the user insert correct information he will write something.
I don't want to open another JFrame I would like that the Login frame will be substitute with another one in order to have only one windows.
Could you tell me the correct object that I must use?
The best options are using either a JOptionPane or a JDialog
JOptionPane works as a message box, and can be customized to your linking and usage. For example, if what you wanna show is a sucessfully logged in message, you could use:
JOptionPane.ShowMessageDialog(null, "Logged in sucessfully", "Logged in", JOptionPane.INFORMATION_MESSAGE);
You can find out about each parameter here. It's a pretty complete documentation of the JOptionPane.
JDialog is another time of window used by Window Builder, and is works as a window that cannot be switched, a classic modal dialog. While this screen is in usage you cannot acess others (as your JFrame), unless you command it to close. And to use this you can simply create it as you would with your Frame. It's modality is set by default.
From what I get of your message the first option would be the best alternative, but that decision's up to you.
I highly recommend you to look into some Window Builder documentation before you'd resort to Stack Overflow. This would be helpfull, it explains everything you need to know about the usage of Window Builder's windows and it's funcionalities.
you can close your current frame by using the command
this.dispose();
this will just close your current window. Just make sure you open the other window too.
JFrame frame = new [yourClassname]();
that should work just fine :)

Java GUI Design view not showing completely but code works

I am new to Java GUI I deigned and window and menu item using java design tool.But when I want to create window for menu item say New contact I did not find an option to do that in event handler so I did it manually by coding it.But when I go to design part and click on New Contact it does not show the window I created via code.
Here is the screen shot of deign view -when I click on New Contact nothing happens.
Now in the source code when I run it I get the window I coded
Is there any possible way I can make it work in design part? I did not find any option to do it in Add Event Handler
You do not want a JFrame to show another JFrame -- that's a bad GUI design since it means that your application is actually two applications. Better to show a dialog window such as a JDialog. Please see The Use of Multiple JFrames, Good/Bad Practice?
If you want to design a 2nd window, create a new Java program in NetBeans, one that creates this second window (again, better for it to be a JDialog, not a JPanel)
Give it a constructor that allows passing in the parent window, and then pass that to the JDialog super constructor
And then in your ActionListener code above, create a new object of this new program, passing in the current JFrame.
In the future, please post code as code-formatted text, not as an image, since this way we can copy, paste, compile and run it if we want, allowing us to better understand your code and your problem.

Custom Java Window Title Bar Menu

I'm trying to allow the user to change the title of a window in Java without adding components to the window itself. I'm actually trying this with a JInternalFrame, but figure the solution should be similar for a JFrame. I simply want to add an additional menu item in the context menu that pops up when right clicking on a window title bar. For example, the Set title below:
This example is on Windows XP, but perhaps there's a way to get the window context menu OS independently perhaps similar to the SystemTray.getSystemTray() (but for individual windows within an application). From this I would be able to provide my own ActionListener to popup a dialog for the user to enter a new title.
Is this a much bigger task than I'm guessing it is? Does anyone have solutions they've used before?
Short answer: I don't think this is easy. I'm not 100% sure if it is possible.
First, JFrame and JInternalFrame are actually quite different. JFrame is a top level component whose title bar and such are typically provided by the OS. JInternalFrame's entire content (including title bar) is provided by the Swing LAF.
For a JInternalFrame, the context menu is provided by the LAF, not JInternalFrame itself. You would have to do something with the UIComponent in order to change the context menu. I think you would likely have to provide a custom UI component in order to do this, which is ugly and typically breaks across different LAFs or works but looks terrible at best. See BasicInternalFrameTitlePane, the createSystemMenu method.
I don't think this is possible without digging way too deep into Swing's internal UI system and I wouldn't even consider doing this. Why don't you use the inbuilt JMenuBar of JInternalFrame?
myInternalFrame.setJMenuBar(myMenuBar);

How to get JOptionPane with three text fields

I want to know how i can do a messageBox from three input dialog ..
Like this:
JOptionPane.showInputMessageDialog("Enter your FirstName");
JOptionPane.showInputMessageDialog("Enter your MiddleName");
JOptionPane.showInputMessageDialog("Enter your LastName");
But I want one message has a three input boxes.
Build a JPanel (supose it's named inputPanel) with the three JtextFields to input and then do this:
if (JOptionPane.YES_OPTION == JOptionPane.showconfirmDialog(
parentComponent, inputPanel, "Enter your data", JOptionPane.YES_NO_OPTION) {
// retrieve data from the JTextFields and do things
} else {
// User close the dialog, do things... or not
}
You can't do that with JOptionPane. Create a JDialog and add three JTextField's to it instead. A JDialog will block the caller when you call setVisible(true), so it's easy to create a dialog that waits for user input before it returns.
showInputMessageDialog and its brethren are simple ways to whip up a simple "standard" dialog. For more complicated dialogs, I'm pretty sure you'll have to subclass JDialog or such.
As Telcontar has suggested you can add Swing components (like a JPanel) to an option pane. So it is easy to take advantage of the automatic creation of buttons rather than do it from scratch by building your own JDialog.
However, there is one small problem. The focus will be on the first button, not on the first component of your panel. To get around this problem you can try the solution presented in Dialog Focus.
You can find the standard Java Tutorial Example here:
Click Here to Open the example java file
The example has only one text box, but the example is clear enough for you to extend it.

How do I get "Goodbye Window" to show up in Java?

I have a Java network application and this is what I want to do:
After user logs out, his interface window closes.
Now, I want for another window to show up that will say something like: "Thank you for using our application".
This final window should be borderless and without any available option, more like a plain picture (jpeg? why not?). By clicking on it, user will be sure to close this final window.
I googled and couldn't fin anything on this matter, it's hard to phrase the question.
I hope someone helps me...
https://docs.oracle.com/javase/1.5.0/docs/api/javax/swing/JWindow.html
A JWindow is a borderless, undecorated JFrame (no titlebar or buttons).
This should be what you need.
This should help:
http://java.sun.com/docs/books/tutorial/uiswing/events/windowlistener.html
You're interested in the windowClosing and windowClosed events
You have various possibilities, depending on when you want this dialog to display :
if you want it to display juste before the app closes, use addShutdownHook
if you want it to display when the last window closes, use addWindowListener
You can then use a JWindow with your image inside, and use addMouseListener to wait for the user to click on it.

Categories

Resources