I have used showSaveDialog in a controller class for an FXML. When a hyperlink is clicked, the showSaveDialog should open a dialog box to save a file. The dialog box to Save file opens up, but it appears behind the fxml from which it is called.
I have to minimize the main fxml and then save the file using the showsavedialog window. Please help
JFileChooser fc = new JFileChooser();
fc.setSelectedFile(new File(fileName));
fc.setDialogTitle("Choose a path to Save file");
int returnVal = fc.showSaveDialog(this);
Related
When you create toolbar with buttons in GTK# in Xamarin Studio it seems that you can only assign images by StockId (Stock.New, Stock.Open etc).
Is there any way to assign custom images to toolbar buttons?
You can pass a Widget as a parameter in the ToolButton constructor:
var tbar = new Toolbar();
var icon = new Image("icon.png");
var button = new ToolButton(icon, "SO");
tbar.Add(button);
In this case, icon.png with no path assigned to it, should exist in the application directory, so set it to "Copy To Output Directory".
You can also create the Image by passing a Gdk image and mask, but that is another story...
How do I add code for a button on a ViewController? For example, in VisualStudio, I can simply double-click on a button and it will take me to an auto-genned clicked handler for the button in the codebehind. How do I go about doing something similar to this in xcode?
Steps to generate button code.
1. Create button using drag and drop from the list of components.
Now click on this button(shown in second image )
It will automatically directs you in your code file.
But if some problems occurs to direct you jn your code file.
Follow this steps.
1. Click on your viewController where you added button. (In viewcontroller scene)
2. Click on the identity inspector check the class name.
3.Check same class name is there in the second part.
If its same than now you can simple using control + three finger and drag it to your .swift file it will open it like this.
Now select action in connection to get button click action. And remains outlet to get the button property.
But if you are not getting the same file select here and find your file name in this hierarchy. After getting file do same process again.
Just do what I say it's simple.
1.Open File Navigator and Select your View's viewController.h file.
2.Now left click on your button and click+control drag to viewController.h (make sure you drag between #interface ---- #end).
3.Give name to your method and make sure You select Action in Connection option.
enter image description here
4.Click connect and you will have your method declaration on viewcontroller.h .
5.Now switch to viewController.m and there you'll find your method at the end and there you will write all the defination of your method.
enter image description here
I'm trying to call modal sheet inside my root window. I've have success with showing sheet but it is not attached to main window.
I've read about similar problem:
Window outlet is set (it is automaticly set by XCode)
Visible at launch option is unchecked.
My application has storyboard (image below), I'm calling sheet from Root Window Controller. I've tried to call sheet from Root Split View Controller but had no success.
let loginWindow = LoginWindowController(windowNibName: "LoginWindowController")
self.window?.beginSheet(loginWindow.window!, completionHandler: { (res) -> Void in
print("completed")
})
I've tried to call beginSheet (also to display sheet you can use presentViewControllerAsSheet or performSegueWithIdentifier) within viewDidLoad method. That was the error.
You can call sheet only after view was appeared. Then sheet will be placed correctly, inside window and without window/view hierarchy errors.
Now I'm calling sheet in viewDidAppear method and everything is working
I'm writing a Cocoa app using the document architecture. Whenever an untitled document is created in this app, the user should be shown a window that lets them pick a template and prompts for other information. Only one of these windows should show up at a time, and preferably it should be possible to interact with the rest of the application while the template chooser is visible. (This is how Pages behaves.)
I've got most of this working by overriding -[NSDocumentController openUntitledDocumentAndDisplay:error:]:
- (id)openUntitledDocumentAndDisplay:(BOOL)displayDocument
error:(NSError *__autoreleasing *)outError {
TsDocument * doc = [self makeUntitledDocumentOfType:self.defaultType
error:outError];
if(!doc) {
return nil;
}
TsNewWindowController * newController = [TsNewWindowController new];
newController.document = doc;
if([NSApp runModalForWindow:newController.window] == NSRunAbortedResponse) {
if(outError) {
*outError = [NSError errorWithDomain:NSCocoaErrorDomain
code:NSUserCancelledError
userInfo:nil];
}
return nil;
}
[self addDocument:doc];
if(displayDocument) {
[doc makeWindowControllers];
[doc showWindows];
}
return doc;
}
However, as you can see, the window is displayed modally, blocking access to the rest of the app. Is there a simple way to achieve what I want without making the template picker modal?
To explain a couple things more clearly:
I do of course know that -runModalForWindow: will run the window modally—it's right there in the name! I'm looking for another way to display the window that will still block -openUntitledDocumentAndDisplay:error:, or that doesn't require me to block the method at all.
I don't believe I can simply create the document, show the newController's window, and call the document's makeWindowControllers and showWindows later because, if the app quits, Restore will not show the template chooser—it shows the normal editing interface.
You do need to create and use a NSWindowController, but you need to do so before openUntitledDocument…:: is called.
In the unreleased Adium Xtras Creator, I tapped in at several points:
In the application's delegate, in applicationOpenUntitledFile:, I show the template-chooser window and return YES.
In the document controller, in removeDocument:, I pass the message on to super, then check whether there are still any documents open. If not, I show the template-chooser window.
In the document controller, in addDocument:, I hide the template-chooser window, then pass to super.
Thus:
If the user tries to create a new document (of no particular type) by any means, the template-chooser will be shown instead.
If the user creates a new document (of an explicit type) by any means, the template-chooser will be hidden. (The application I did this in had its “New” menu item set up as a submenu containing specific types.)
If the user opens any document by any means, the template-chooser will be hidden.
If the user closes the last open document, the template-chooser will be shown.
If the user or another application tries to reopen the application by any means, the template-chooser will be shown.
You are calling runModalForWindow: so of course it's running the window as a modal window.
Why not just show the window instead? Use an NSWindowController and call showWindow: to display the template window. In your window controller, implement actions that react to the user's selection and then create the appropriate document (or cancel).
I don't think you need to actually create a document in openUntitledDocumentAndDisplay:error:.
I am very new to mac programming. Just started before 3 days.
I am making a sample app in which i have one button in main window
I am using this code to open a new wndowcontroller
ThirdViewController *tvc = [[ThirdViewController alloc] initWithWindowNibName:#"SecondViewController"];
[tvc showWindow:self];
This working fine but when i press button again it will open same window again so after every click i have +1 window on screen.
What i want is if my new window is already on my screen then button can't add same window.
Thanks in advance:)
If that code is being executed whenever the button is clicked then you’re effectively creating a new window controller, loading its window from a nib file, and showing that window as many times as the button is clicked.
The standard approach to prevent this from happening is having an instance variable that is initially nil and assigning it a window controller only once. Subsequently, the instance variable is not nil any longer and you can test that to avoid creating another controller and loading the nib file again.
You could, for example, declare the following instance variable in your application delegate or whatever controller should be responsible for the third window controller:
ThirdViewController *tvc;
and, when the button is clicked:
if (nil == tvc) {
// If tvc is nil then it's the first time this code is being executed
tvc = [[ThirdViewController alloc] initWithWindowNibName:#"SecondViewController"];
}
[tvc showWindow:self];