java - JFrame as a dialog


Question: 

I want to customize the jframe and that frame should work like a joptionpane. which is relative with parent. can i do like this. if it is possible please any one help me.




2 Answers: 

With a little bit of research, the answer to your question is more accessible than you think.

No use reinventing the wheel. Just use a JDialog instead of a hacked JFrame.

Also, please consider putting a little bit more effort in your questions. The quality of answers mirror the quality of the question.

 

Below are a few examples of Dialogs with JFrames. Trying to customize a JFrame with a dialog is likely to be very unnecessary as these are just a few from a large range of dialogs you can utilize.

Also as GCrec has referenced, there are the tutorials on Oracle which can give you more of a description.

  public class SO {

public static void main(String[] args) {

    //Shows a GUI to allow typed input        
    String showInput = JOptionPane.showInputDialog(new JFrame(), "Enter some input:");
    //Shows a GUI displaying a message, in this case the typed input
    JOptionPane.showMessageDialog(new JFrame(), showInput);
    //A confirmation dialog for choosing yes or no
    JOptionPane.showConfirmDialog(new JFrame(), "Was that correct?");
    //Options for the below GUI where you have a range of options.  The int response 
    //varies depending on what you select. Then use something like an if statement to react to the input
    String[] options = {"Red", "Blue", "Green"};
     int response = JOptionPane.showOptionDialog( null, "Favorite Colour?", "Choice?", JOptionPane.YES_NO_OPTION    , JOptionPane.PLAIN_MESSAGE , null, options, "Wide Search");


    //The one you probably want, the JDialog which is basically a JFrame with a file selection dialog inside         
     FileDialog fc = new FileDialog(new JFrame(), "File Dialog");
    fc.setVisible(true);
    String selectedFile = fc.getFile();
     System.out.println("You have selected: " + selectedFile);
     File f = new File(selectedFile);
     JOptionPane.showMessageDialog(new JFrame(), f.getAbsolutePath());
}

Hope this helps! Good luck

 

More Articles


java - How to integrate KNET payment gateway with php

How can I integrate the KNET payment gateway with PHP? The gateway id only works with Java and .NET.

c# - Microsoft Bot Framework works locally, but fails remotely

I have this bot that is fairly complicated, but it works locally. But as soon as I publish it, it fails with the error: Sorry, my bot code is having an issue.I have tried using Application Insights, but it isn't showing the error details.The error always happens at the same point:/// <summary>

c# - How to connect with bot from another app?

I have created a core bot with basic workflow to collect information from end-users, which is hosted on http://localhost:3978, and exposes an endpoint to send message http://localhost:3978/api/messages (POST) I can start and chat with bot via Bot Framework Emulator, but I dont know how to interact w


c# - Set time limit for items in container in CosmosDB using Microsoft.Bot.Builder.Azure (bot framework v4)

I want to set the time to live for the items in a container in cosmosDB, but I am not sure how to do so using the config of cosmosdb storage in bot framework v4. I would appreciate some help on this matter.I have read about setting time to live using DocumentClient() as documented here. However I se

java - Paypal expressCheckout integration (DoExpressCheckout) error

I have a ExpressCheckout integration setup in java google app engine and it working up to GetExpresschekout .but in finall call(DoExpressCheckout) I am unable to Authorize payment .it returnsan errorRESULT=1000&PNREF=E24P1FBB8FA4&RESPMSG=Generic processor error: 13116-The transaction is in p

Magento Payment methods are not showing in checkout

I have a website in magento. iam using payment methods paypal, bank transfer and stripe. using multi store view(3)Except paypal remaning payment methods are not showing in checkout process. i dont know what to do. please help me any one,Thanks,


payment processing - pylons/python

I'm building an application that eventually needs to process cc #s. I'd like to handle it completely in my app, and then hand off the information securely to my payment gateway. Ideally the user would have no interaction with the payment gateway directly.Any thoughts? Is there an easier way?

Google Smart Home Action: Account linking successful, SYNC response sent by fulfillment with status code 200 but Google Home app reporting error

I am building a Google Smart Home action with fulfillment hosted on AWS as a lambda function in node.js with the node implementation for Google Smart Home actions, exposed via AWS API gateway and an external OAuth 2 provider serving as authorizer for API gateway. My fulfilment includes SYNC, QUERY a

Xcode: App installation failed No code signature found

I want run app on real device ( iphone 6 or 8 )But i get this error : App installation failed No code signature found.I try all below solutions but not work for me:iOS app testing. App installation failed. No code signature foundMy xcode version is 9.2I'm tired :(

How do I force my Google home to download latest version of the local app

I'm developing the smart device handler using Google Home Local SDK. How do I force device to reload and restart the app? (now I have to unplug the power cord, it does not looks good as it sparks)also I have a couple of Google Home devices, how do I tell which of them should execute requests, is it