Button exiting swing ..closing

hi i want to close or hide a jpanel attached into another
i have a Jframe1 inserted into another by using:
myPanel1 = new javax.swing.JPanel();
JPanel param =(JPanel) new JFrame1().getContentPane();
myPanel1 .add(param);
So i see "param" panel attached into mypanel1.
Now param panel have a button that say : "CLOSE"
but i cant close param panel using setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); as a actionperform method
What can i do?
Thanks for helping!!
greetings!!

You're doing a very strange thing there: by adding the frame's content pane to your other panel (where do you put that?) you're removing the content pane from the frame.
I suspect you want to do this:
JPanel myPanel = createMyPanel();
JFrame f = new JFrame();
f.getContentPane().add(myPanel); // or, f.setContentPane(myPanel);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);...but I'm not sure I fully understand what you're trying to do.

Similar Messages

  • How can I prevent Firefox from cleaning my clipboard at exit (exit or closing firefox) ?

    How can I prevent Firefox from cleaning my clipboard at exit (exit or closing firefox) ?
    I am using FF 9.0.1 and the problem start from FF 5.0

    You can't prevent that.<br />
    If you've placed data on the clipboard in Firefox then you need to paste that data in the other program, if that is your intention, before closing Firefox.

  • Making a button visible upon closing a document

    Kind of a weird question, but is there a way to make a button visible upon closing a document? Here's my situation. I want users to click a link which will open a PDF. I then want the users to take a quiz based off of the information in the PDF. Is there a way to have the users click the link to open the PDF, then a button to start a quiz becomes visible when the users close the PDF? I have a feeling it's probably not possible, but I figured I'd check. Thanks.

    I was actually able to find a bit of a workaround. I created an advanced action to open the PDF and show the button (it was hidden to begin with) once I click the hyperlink. It's not exactly what I wanted to do, but I think it'll suffice until I figure out a way to show the button upon closing the PDF. I'll look into the java scripting, even though I'm not really a coder. Thanks!

  • Shortcut on Button in swing

    Dear Sir,
    Can i get help from you any one to create shortcut on button in swing like press ENTER to process.
    I am so worried that how do it.
    I am waiting so anxiously for u reply.
    Regards,
    Shah Jehan

    If it is not a default button - use mnemonic.
    Default button reacts on "Enter" key press. Use JRootPane.setDefaultButton(), and JButton.requestFocusInWindow() if needed.

  • How to pop a virtual calendar with a click of button in swing applications

    How to pop a virtual calendar with a click of button in swing applications
    Does anyone knows how to pop up a virtual calendar in swing applications when there is a click of button. Do u have any components plug in tutorials or free java components download. Does java allows to used Microsoft calendar active x to plug into java applications. Thanks

    If you want a simple date picker, try this one
    http://forum.java.sun.com/thread.jspa?threadID=620699&messageID=3497753its a stand alone, but can be easily modified to include in a popup, and,
    instead of displaying the date:
    - passing the 'date picked' back to the calling object
    - close the popup

  • How do you make the "Continue" button exit project on quiz attempt results page

    When the project quiz is finished, on the quiz results slide it has a continue button to press, but seems worthless since it just turns into a black screen when finished instead of closing the project like you think it should. Any suggestions on how to make that button close the project?

    Closing projects only works reliably when publishing to EXE format.  Web browser security often prevents HTM/SWF content windows from being closed in the same way.
    Try placing a slide AFTER your quiz results slide so that the Continue button has somewhere to go to.  Then change your Preferences > Project > Start and End > Project End Options > Action to Close Project.  This way, the project is trying to close down naturally, not as a result of clicking a button.  You can make this final slide as short as you like, but a second or so is usually good just in case you have Preferences set to Fade Out On Last Slide.

  • How do I change the color of a button in swing?

    I'm using swing to create an interface and it's made up mainly of buttons. Gray isn't exactly the prettiest of colors and I'd love if I could change the color.
    Cheers,
    elmicko

    Hi!
    You can set the color of each button independently using:
    JButton1.setBackground(Color.BLUE); // for the background
    JButton1.setForeground(Color.CYAN); // for the text displayedOr if you want all the button to have the same color you can overwrite the look and feel of the application using:
    javax.swing.UIManager.put("Button.background", new Color(230, 230, 230));

  • System.exit(0) closing both JFrames

    hey, ive got a problem with a JFrame
    Ive got 1 JFrame that currently holds a JMenuBar, 2 JMenus and in the 1st JMenu there are 4 JMenuItems.
    One of the JMenuItems uses an ActionListener to lauch another JFrame, but when the 2nd JFrame is finished (and System.exit(0) launches), the first JFrame closes as well. What is going on??
    code follows:
    THE MAIN JFRAME
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class realframe extends JFrame
    protected JMenuItem[] m_fontMenus;
    protected JCheckBoxMenuItem m_showPatList;
    protected JCheckBoxMenuItem m_showPatData;
    protected JCheckBoxMenuItem m_showHRGraph;
    protected JCheckBoxMenuItem m_showBPGraph;
    protected JCheckBoxMenuItem m_showTempGraph;
    public realframe(){
    super("PMS Menu GUI");
    setSize(450, 350);
    JMenuBar menuBar = createMenuBar();
    setJMenuBar(menuBar);
    WindowListener wndCloser = new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    addWindowListener(wndCloser);
    setVisible(true);
    //start Menus
    protected JMenuBar createMenuBar()
    final JMenuBar menuBar = new JMenuBar();
    //creates File
    JMenu mFile = new JMenu("File");
    //Menu 1 item 1 : : : Add Patient
    JMenuItem item = new JMenuItem("Add Patient");
    ActionListener lst = new ActionListener() //ActionListener for Add Patient
    public void actionPerformed(ActionEvent e)
    new realgui( new JFrame() );
    item.addActionListener(lst);
    mFile.add(item);
    //Menu 1 item 2 : : : Delete Patient
    item = new JMenuItem("Delete Patient");
    lst = new ActionListener()
    public void actionPerformed(ActionEvent e) { }
    item.addActionListener(lst);
    mFile.add(item);
    //Menu 1 item 3 : : : Search
    item = new JMenuItem("Search");
    lst = new ActionListener()
    public void actionPerformed(ActionEvent e) { }
    item.addActionListener(lst);
    mFile.add(item);
    //Divider
    mFile.addSeparator();
    //Menu 1 item 4 : : : Exit
    item = new JMenuItem("Exit");
    item.setMnemonic('x');
    lst = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    System.exit(0);
    item.addActionListener(lst);
    mFile.add(item);
    menuBar.add(mFile);
    //end menu item 1
    ActionListener viewListener = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    updateMonitor();
    JMenu mView = new JMenu("View");
    mView.setMnemonic('V');
    //Menu 2 item 1 : : : Patient List Toggle
    m_showPatList = new JCheckBoxMenuItem("Patient List");
    m_showPatList.setMnemonic('L');
    m_showPatList.setSelected(true);
    m_showPatList.addActionListener(viewListener);
    mView.add(m_showPatList);
    //Menu 2 item 2 : : : Data box Toggle
    m_showPatData = new JCheckBoxMenuItem("Patient Data");
    m_showPatData.setMnemonic('D');
    m_showPatData.setSelected(true);
    m_showPatData.addActionListener(viewListener);
    mView.add(m_showPatData);
    //Divider
    mView.addSeparator();
    //Menu 2 item 3 : : : HR Graph toggle
    m_showHRGraph = new JCheckBoxMenuItem("Show HR Graph");
    m_showHRGraph.setMnemonic('H');
    m_showHRGraph.setSelected(true);
    m_showHRGraph.addActionListener(viewListener);
    mView.add(m_showHRGraph);
    //menu 2 item 4 : : : BP Graph Toggle
    m_showBPGraph = new JCheckBoxMenuItem("Show BP Graph");
    m_showBPGraph.setMnemonic('B');
    m_showBPGraph.setSelected(true);
    m_showBPGraph.addActionListener(viewListener);
    mView.add(m_showBPGraph);
    //menu 2 item 5 : : : Temp Graph Toggle
    m_showTempGraph = new JCheckBoxMenuItem("Show Temp Graph");
    m_showTempGraph.setMnemonic('T');
    m_showTempGraph.setSelected(true);
    m_showTempGraph.addActionListener(viewListener);
    mView.add(m_showTempGraph);
    menuBar.add(mView); //adds the menu
    return menuBar;
    protected void updateMonitor() { }
    public static void main(String argv[]) { new realframe(); }
    THE SECONDARY JFRAME
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.*;
    import java.awt.event.*;
    public class realgui extends JDialog implements ActionListener
    JTextField surname;
    JTextField given;
    JTextField age;
    JTextField doctor;
    JTextField phone;
    Patient patient = new Patient();
    JRadioButton radiomale;
    JRadioButton radiofemale;
    public realgui( JFrame frame )
    super( frame, true );
    System.out.println("in 1");
    setTitle( "Add A New Patient" );
    setSize( 400, 250 );
    JPanel panel = new JPanel( new BorderLayout() );
    panel.setLayout( new GridBagLayout() );
    panel.setBorder( new EmptyBorder( new Insets( 5, 5, 5, 5 ) ) );
    getContentPane().add( BorderLayout.CENTER, panel );
    GridBagConstraints c = new GridBagConstraints();
    Dimension shortField = new Dimension( 40, 20 );
    Dimension mediumField = new Dimension( 100, 20 );
    Dimension longField = new Dimension( 180, 20 );
    EmptyBorder border = new EmptyBorder( new Insets( 0, 0, 0, 10 ) );
    EmptyBorder border1 = new EmptyBorder( new Insets( 0, 20, 0, 10 ) );
    c.insets = new Insets( 2, 2, 2, 2 );
    c.anchor = GridBagConstraints.WEST;
    JLabel lbl1 = new JLabel( "Surname:" );
    lbl1.setBorder( border );
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 1;
    panel.add( lbl1, c );
    surname = new JTextField();
    surname.setPreferredSize( longField );
    c.gridx = 1;
    c.gridwidth = 3;
    panel.add(surname, c );
    JLabel lbl7 = new JLabel( "Given Name:" );
    lbl7.setBorder( border );
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = 1;
    panel.add( lbl7, c );
    given = new JTextField();
    given.setPreferredSize( longField );
    c.gridx = 1;
    c.gridwidth = 3;
    panel.add(given, c );
    JLabel lbl2 = new JLabel( "Age:" );
    lbl2.setBorder( border );
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = 1;
    panel.add( lbl2, c );
    age = new JTextField();
    age.setPreferredSize( shortField );
    c.gridx = 1;
    c.gridwidth = 3;
    panel.add( age, c );
    JLabel lbl3 = new JLabel( "Gender:" );
    lbl3.setBorder( border );
    c.gridx = 0;
    c.gridy = 3;
    panel.add( lbl3, c );
    JPanel radioPanel = new JPanel();
    radioPanel.setLayout( new FlowLayout( FlowLayout.LEFT, 5, 0 ) );
    ButtonGroup group = new ButtonGroup();
    radiomale = new JRadioButton( "Male" );
    radiomale.setSelected( true );
    group.add(radiomale);
    radiofemale = new JRadioButton( "Female" );
    group.add(radiofemale);
    radioPanel.add(radiomale);
    radioPanel.add(radiofemale);
    c.gridx = 1;
    c.gridwidth = 3;
    panel.add( radioPanel, c);
    JLabel lbl4 = new JLabel( "Doctor:" );
    lbl4.setBorder( border );
    c.gridx = 0;
    c.gridy = 4;
    panel.add( lbl4, c );
    doctor = new JTextField();
    doctor.setPreferredSize( longField );
    c.gridx = 1;
    c.gridwidth = 3;
    panel.add(doctor, c );
    JLabel lbl5 = new JLabel( "Phone Number:" );
    lbl5.setBorder( border );
    c.gridx = 0;
    c.gridy = 5;
    c.gridwidth = 1;
    panel.add( lbl5, c );
    phone = new JTextField();
    phone.setPreferredSize( mediumField );
    c.gridx = 1;
    c.gridwidth = 3;
    panel.add(phone, c );
    JButton submitBtn = new JButton( "Submit" );
    c.gridx = 4;
    c.gridy = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    panel.add( submitBtn, c );
    submitBtn.addActionListener(this);
    JButton cancelBtn = new JButton( "Cancel" );
    c.gridy = 1;
    c.anchor = GridBagConstraints.NORTH; // anchor north
    panel.add( cancelBtn, c );
    cancelBtn.addActionListener(this);
    WindowListener wndCloser = new WindowAdapter()
    public void windowClosing(WindowEvent e)
    System.exit(0);
    addWindowListener( wndCloser );
    setVisible( true );
    public static void main( String[] args ) {
    new realgui( new JFrame() );
    public void actionPerformed(ActionEvent evt)
    if (evt.getActionCommand ().equals ("Submit"))
    Person person = new Person();
    String surnam = surname.getText();
    String give = given.getText();
    String ag = age.getText();
    String docto = doctor.getText();
    String phon = phone.getText();
    char gende;
    if(radiomale.isSelected()==true)
    gende = 'M';
    else
    gende = 'F';
    System.out.println("in 2 " + surnam);
    person.setSurname(surnam);
    person.setGiven(give);
    // person.setAge(ag);
    person.setDoctor(docto);
    person.setPhone(phon);
    person.setGender(gende);
    System.out.println(surnam + " " + give + " " + ag + " " + gende + " " + docto + " " + phon);
    person.setHistory();
    patient.add(person);
    System.exit(0);

    No, dispose() is inherited. Just replace System.exit(0); with:
    setVisible(false);
    dispose();I think that'll work in your code.

  • Loading and displaying other  form on click of a button using swing

    hi,
    i've just started with my first ever swing program. i want to load another UI form on click of a button . how can i do that.

    Sorry for posting last message
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class MainCl extends JFrame
    public MainCl()
    this.setBounds(100,100,400,300);
    btn = new JButton("Click me to show another fframe");
    btn.setBounds(10, 20, 250, 30);
    this.getContentPane().setLauout(null)
    this.getContentPane().add(btn);
    btn..addActionListener(new ActionListener()
    JFrame frm2 = new SecondFrame();
    frm2.setVisible(true);
    public static void main(String [] args)
    JFrame frm1 = new MainCl();
    frm1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frm1.setVisible(true);
    JButton btn;
    class SecondFrame extends JFrame
    public SecondFrame()
    this.setBounds(200,200,200,100)
    this.getContentPane().add(new JLabel("This is NEW FORM"));
    }

  • How to create a BRowse button using Swing?

    I want to create a browse button with the help og which i want to browse a file..
    please can anyone help me

    Bookmark the API (or search the downloads section if you want to get an offline set)
    {color:0000ff}http://java.sun.com/javase/6/docs/api/{color}
    JFileChooser:
    {color:0000ff}http://java.sun.com/javase/6/docs/api/javax/swing/JFileChooser.html{color}
    db

  • The correct way to exit Swing app?

    Just want to be sure, what is the best and correct way to exit standalone Swing application?
    Right now I can't think of anything better then System.exit(0);*

    How about setting the main JFrame's setDefaultCloseOperation to JFrame.EXIT_ON_CLOSE, and then when you want to exit, calling dispose on this JFrame?

  • Badi/Exit after closing original in DMS

    Hello All,
    I came across a requirement that need to display a popup when closing the original after doing changes.
    SAP standard behavior: If we click on change original button,original( For eg: Word document) will open to edit ,but CV02N will jump back to the search results.If we open the document again in CV02n,document info record will be unlocked as below
    To Avoid this , i need to display a popup ('Document is changed,do you want to Check-in')as soon as original is closed.
    To identify BADI in se24 i put a break point and executed the CV02N .
    But after closing the original ,break point is not getting triggered.
    If some one came across the same requirement earlier,please help me out.
    Thanks
    Naresh Bammidi

    Hello All,
    Below is my requirement,
    My requirement is when i change original and closing the original( eg: Word doc ) then this popup should display.
    We found one standard include in sap system LCV150TOP which is having the code to display the popup.
    We have put the break point and closed the document.But it is not triggering.
    Above requirement is impemented in other country.Below is the functionality.
    DIR screen :
    After click on change original ,Word document is opening
    Edited the document and closed it,one popup is coming as below
    Above popup is coming because of the include lcv150top.
    To achieve this above functionality do we need to implement any SAP Note?
    Please suggest me .
    Thanks
    Naresh

  • Save the contents into hard disk on click of Save As button in Swing

    Hi,
    I have a JButton "Save As". On clicking the button, the contents in the JTextArea should be saved in the local hard disk by opening a Save As dialog box and allowing the user to save in any location.
    Is it possible to do this? If so, please inform me how it could be done.

    Hi,
    Please find the code below.
    try{
    File f = new File("Out.txt");
    FileInputStream fis = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fis); DataInputStream dis = new DataInputStream(bis); String stb = null;
    JDialog w = null;
    stb = new String();
    stb = dis.readLine();
    if(stb != null){
    w = new JDialog();
    final Container c = w.getContentPane();
    c.setLayout(null);
    w.setContentPane(c);
    w.setResizable(true);
    w.setTitle("Log Window");
    w.setSize(330,500);
    final JTextArea jt = new JTextArea();
    JScrollPane jsp = new JScrollPane(jt);
    jt.setLineWrap(true);
    jt.setText("Records not available for the id's"+"\n"+stb);
    jt.setBounds(10,10,285,500);
    final JButton jbSave = new JButton("Save File As");
    JPanel spacer = new JPanel();
    spacer.setMinimumSize(new Dimension(50, 18));
    spacer.setPreferredSize(new Dimension(50, 18));
    JPanel jpButtons = new JPanel();
    jpButtons.add(jbSave);
    jpButtons.add(spacer);
    jpButtons.setBorder(BorderFactory.createEtchedBorder());
    JScrollPane scroll = new JScrollPane();
    c.setLayout(new BorderLayout());
    c.add(jt,BorderLayout.CENTER);
    c.add(jpButtons, BorderLayout.SOUTH);
    jbSave.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
    JFileChooser fileChooser = new JFileChooser();
    int userOption = fileChooser.showSaveDialog(null);
    if(userOption == JFileChooser.APPROVE_OPTION)
    //*******************STATEMENTS TO BE ADDD****************** }
    jt.getText()-----This is how I can get the contents from JTextArea.
    But how I can save the contents. i.e on click of Save As button, Save dialog box opens, and I can choose the location and give the name. but if I go to the location I don't find the file....
    Please guide me to finish this....
    Thanks in Advance.....

  • Question about  Buttons in swing

    How i can have circular button in GUI program.

    This code will get u through :
    JButton button = new JButton(new ImageIcon("roundImage.gif"));
    button.setBorderPainted(false);
    button.setContentAreaFilled(false);
    button.addActionListener(......);
    [email protected]

  • Opening a web overlay frame via button press (and closing it again)

    Hi all
    Is the following possible:
    Push a button
    A web content overlay window opens, displaying the web-based content within the frame (in this case, a URL pasted in from a google mobile search result). This window is smaller than the normal page size, so around 200 x 550px
    Push the same button to close it, returning the page to the original state
    The web content overlay launches automatically, but there's no 'hidden until triggered' option, as per the button panel.
    I don't want the reader to have to 'leave' the app and go to the relevant full page browser via the folio (or Safari).
    Many thanks
    Martyn

    So there is no way to restrict the readerd access to the 'second' page, so it's only accessible via the button tha triggers the web overlay? Do the other apps you mention have the same issue - that the user can reach the duplicate page just by navigating as normal.
    Anyway, I'm using the button method as suggested, made two pages etc. I've created the button, and made it jump to the other duplicate page, only problem is that the new page 'swipes' in, very quickly, which kind of negates the pop-up effect of using a web overlay window. Is there any way to make the duplicate page appear instantly over the old page (without pushing in from the bottom)?
    Thanks
    M

Maybe you are looking for