Locking a JFrame

Hi,
Please exscuse the subject - I will have to explain...
I have an application which has an 'About Box' i.e. Copyright Notice etc. When the user clicks on 'About', the application launches a new JFrame.
I want this new JFrame to sit above the existing application JFrame, and not allow the user to return to the main application window until they have closed the About JFrame.
How do I 'lock the user' into this About Box JFrame until they have either clicked an OK button or closed the window.
Thanks in advance.

Use JOptionPane . It gives you facility to launch variety dialogs .

Similar Messages

  • Locking a JFrame in the screen

    Help!!!!!, How can i lock a JFrame in the screen???
    I mean, no matter what others applications are open (or start the user after my java app) my frame will be at the front of all always.

    thats what I though too, but I has never done that.
    Do you know where could i find some documentation or code examples of programs than manipulate the OS in java???

  • Rookie: Lock a JFrame

    Hi!
    I just have a small question:
    I have a program with a menu window. When I press a button on the menu, a new window pops up.
    My question is:
    How can I lock this new window until the user presses the close button (witch I have made) or the x on the top right corner? By "lock" I mean that it is not possible to press any of the other windows in my program when this window is active...
    I cant find the method (if there is any)...
    Thank you!

    I dont know how to do that.... isnt there a method that I can just put into my JFrame that tells it that it is the only JFrame in the program that can be used at this time (until the JFrame is closed)

  • Drawing a picture within JFrame when I've already created a JFrame

    Hi everyone,
    I was wondering if you could help me out with this problem I'm getting. I'm creating a program to simulate an 'elevator.' When first creating the project I created a brand new 'Java GUI Form' : 'JFrame Form'. From here I went on to drag-and-drop various command buttons and labels to create the user interface (the 'inside' of an elevator). Here is where my question comes in. On the very left of my interface I want to have the program draw a simulation of a box (the elevator) moving up and down with the 'floor numbers' the user pushes. However i don't know how to access the coding of the jFrame object that I created through the design editor so i can input the coding.
    First Question: What do i have to 'write' that would force that box to print into the current JFrame?
    Second Question: What Code (and where do i put it) essentially 'locks' the JFrame from being resized?

    Here, maybe by putting this it might help you recognize what i'm trying to say. The code i'm trying to put in is:
    JFrame window = new JFrame ("Drawing");
            window.setBounds(200,200,700,500);
            window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            window.setVisible(true);
            Container contentPane = window.getContentPane();
            contentPane.setBackground(new Color(125, 125, 125));
            Graphics g = contentPane.getGraphics();* This is a portion of the code
    When run, this program creates a NEW JFRAME WINDOWS, i'm trying to make it run inside an already existing JFrame, whose variable Name i dont know how to find.

  • Help ! To Lock  The Position Of a JFrame ?!!

    hi..
    How can i lock the Position of a JFrme..
    my requirement is to lock the position of a JFrame.. so that it cannot be dragged on a screen.. but must be resizable... is that possible ?
    any suggestions ??
    Thanking You in advance...
    _rG.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    well sorry..
    i guess you are speaking with respect to windows ..
    well i left out to tell ya..
    i'm working on a macintosh..
    so i need the requirement as per the client to lock its position but not the size...
    the desktop on a macintosh can be viewed else with short keys..
    any help ?!!
    _rG.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Keyboard-lock of swing program on Linux box

    We are developing swing program on Linux, and we often meet keyboard-lock issues.
    I try to simplify some of them to small programs, and still meet keyboard-lock.
    Here I post two programs to show the error:
    //---first ----------------------------------------------
    package test;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    public class KeyLock extends JFrame {
      JPanel contentPanel = new JPanel();
      JPanel wizardToolPan = new JPanel();
      JButton btnBack = new JButton("Back");
      JButton btnNext = new JButton("Next");
      JButton btnAbout = new JButton("About");
      public static final String aboutMsg =
              "<html>  This program will help to find keyboard lock problems, two way to reproduce:<br><br>" +
              "1 - press Alt+N to navigate next, and don't release keys untill there are no more next page, <br>" +
              "then try Alt+B to navigate back and also don't release keys untill page 0,<br>" +
              "repeat Alt+N and Alt+B again and again, keyboard will be locked during navigating. <br><br>" +
              "2 - press Alt+A in main window, it will popup an about dialog,<br>" +
              "then press down space key and don't release, <br>" +
              "the about dialog will be closed and opened again and again,<br>" +
              "keyboard will be locked sooner or later." +
              "</html>";
      public KeyLock() {
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setTitle("Keyboard lock test");
        getContentPane().setLayout(new BorderLayout());
        btnBack.setMnemonic('B');
        btnBack.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            KeyLock.this.goBack(e);
        btnNext.setMnemonic('N');
        btnNext.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            KeyLock.this.goNext(e);
        btnAbout.setMnemonic('A');
        btnAbout.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(KeyLock.this, aboutMsg, "About", JOptionPane.INFORMATION_MESSAGE);
        contentPanel.setLayout(new BorderLayout());
        contentPanel.setPreferredSize(new Dimension(400, 250));
        contentPanel.setMinimumSize(new Dimension(400, 250));
        wizardToolPan.setLayout(new FlowLayout());
        wizardToolPan.add(btnBack);
        wizardToolPan.add(btnNext);
        wizardToolPan.add(btnAbout);
        this.getContentPane().add(contentPanel, java.awt.BorderLayout.CENTER);
        this.getContentPane().add(wizardToolPan, java.awt.BorderLayout.SOUTH);
        this.setSize(400, 300);
        this.createContentPanels();
        this.showCurrent();
      private Vector<JPanel> slides = new Vector<JPanel>();
      private int current = 0;
      private void createContentPanels() {
        for (int j = 0; j < 20; ++j) {
          JPanel p = new JPanel(new FlowLayout());
          p.add(new JLabel("Page: " + j));
          p.add(new JTextField("Page: " + j + ", input something here", 20));
          p.add(new JTextField("Page: " + j + ", input something here", 20));
          p.add(new JTextField("Page: " + j + ", input something here", 20));
          p.add(new JLabel("Input something in password box:"));
          p.add(new JPasswordField(20));
          p.add(new JCheckBox("Try click here, focus will be here."));
          p.add(new JRadioButton("Try click here, focus will be here."));
          slides.add(p);
      public void showCurrent() {
        if (current < 0 || current >= slides.size())
          return;
        JPanel p = slides.get(current);
        this.contentPanel.add(p, java.awt.BorderLayout.CENTER);
        this.pack();
        Component[] comps = p.getComponents();
        if (comps.length > 0) {
          comps[0].requestFocus(); // try delete this line
        this.repaint();
      public void goNext(ActionEvent e) {
        if (current + 1 >= slides.size())
          return;
        this.contentPanel.remove(slides.get(current));
        current++;
        sleep(100);
        this.showCurrent();
      public void goBack(ActionEvent e) {
        if (current <= 0)
          return;
        this.contentPanel.remove(slides.get(current));
        current--;
        sleep(100);
        this.showCurrent();
      public static void sleep(int millis) {
        try {
          Thread.sleep(millis);
        } catch (Exception e) {
          e.printStackTrace();
      public static void main(String[] args) {
        KeyLock wizard = new KeyLock();
        wizard.setVisible(true);
    }The first program will lead to keyboard-lock in RHEL 4 and red flag 5, both J2SE 5 and 6.
    //---second -----------------------------------------
    package test;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class KeyFocusLost extends JFrame {
      private JButton btnPopup = new JButton();
      private JTextField jTextField1 = new JTextField();
      private JPasswordField jPasswordField1 = new JPasswordField();
      private JPanel jPanel1 = new JPanel();
      private JScrollPane jScrollPane3 = new JScrollPane();
      private JTree jTree1 = new JTree();
      private JButton btnAbout = new JButton("About");
      public static final String aboutMsg =
              "<html>  This program is used to find keyboard focus lost problem.<br>" +
              "Click 'popup' button in main window, or select any node in the tree and press F6,<br>" +
              "a dialog popup, and click ok button in the dialog,<br>" +
              "keyboard focus will lost in main window." +
              "</html>";
      public KeyFocusLost() {
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setTitle("Keyboard focus test");
        getContentPane().setLayout(null);
        btnPopup.setBounds(new Rectangle(33, 482, 200, 35));
        btnPopup.setMnemonic('P');
        btnPopup.setText("Popup and lost focus");
        btnPopup.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            PopupDialog dlg = new PopupDialog(KeyFocusLost.this);
            dlg.setVisible(true);
        btnAbout.setBounds(new Rectangle(250, 482, 100, 35));
        btnAbout.setMnemonic('A');
        btnAbout.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(KeyFocusLost.this, aboutMsg, "About", JOptionPane.INFORMATION_MESSAGE);
        jTextField1.setText("Try input here, and try input in password box below");
        jTextField1.setBounds(new Rectangle(14, 44, 319, 29));
        jPasswordField1.setBounds(new Rectangle(14, 96, 319, 29));
        jPanel1.setBounds(new Rectangle(14, 158, 287, 291));
        jPanel1.setLayout(new BorderLayout());
        jPanel1.add(new JLabel("Select any node in the tree and press F6."), java.awt.BorderLayout.NORTH);
        jPanel1.add(jScrollPane3, java.awt.BorderLayout.CENTER);
        jScrollPane3.getViewport().add(jTree1);
        Object actionKey = "popup";
        jTree1.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0), actionKey);
        jTree1.getActionMap().put(actionKey, new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            PopupDialog dlg = new PopupDialog(KeyFocusLost.this);
            dlg.setVisible(true);
        this.getContentPane().add(jTextField1);
        this.getContentPane().add(jPasswordField1);
        this.getContentPane().add(jPanel1);
        this.getContentPane().add(btnPopup);
        this.getContentPane().add(btnAbout);
      public static void main(String[] args) {
        KeyFocusLost keytest = new KeyFocusLost();
        keytest.setSize(400, 600);
        keytest.setVisible(true);
      static class PopupDialog extends JDialog {
        private JButton btnOk = new JButton();
        public PopupDialog(Frame owner) {
          super(owner, "popup dialog", true);
          setDefaultCloseOperation(DISPOSE_ON_CLOSE);
          this.getContentPane().setLayout(null);
          btnOk.setBounds(new Rectangle(100, 100, 200, 25));
          btnOk.setMnemonic('O');
          btnOk.setText("OK, then focus lost");
          btnOk.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              PopupDialog.this.getOwner().toFront();
              try {
                Thread.sleep(100); // try delete this line !!!
              } catch (Exception ex) {
                ex.printStackTrace();
              PopupDialog.this.dispose();
          this.getContentPane().add(btnOk);
          this.getRootPane().setDefaultButton(btnOk);
          this.setSize(400, 300);
    }The second program will lead to keyboard-focus-lost in RHEL 3/4 and red flag 4/5, J2SE 5, not in J2SE 6.
    And I also tried java demo program "SwingSet2" in red flag 5, met keyboard-lock too.
    I guess it should be some kind of incompatibleness of J2SE with some Linux platform. Isn't it?
    Please help, thanks.

    Hi.
    I have same problems on Ubuntu with Java 6 (all versions). I would like to use NetBeans or IntelliJ IDEA but it is not possible due to keyboard locks.
    I posted this bug
    https://bugs.launchpad.net/ubuntu/+bug/174281
    before I found some info about it:
    http://forums.java.net/jive/thread.jspa?messageID=189281
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6506617
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6568693
    I don't know from which part this bug comes, but I wonder why it isn't fixed yet. Does anybody else use NetBeans or IntelliJ IDEA on linux with Java 6 ?
    (I cannot insert link :\ )

  • Locked table columns in JTable?

    Does anyone know if a JTable can implement locked columns? By which I mean, I'd like to nominate 1 or more columns that remain locked to the left (or even right) of the table display and don't scroll out of view when scrolling horizontally.
    I can imagine some round-about ways of doing it, but I wonder if there's a simple way to do it.
    Thanks
    Iain

    Here is my attempt at this:
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    public class FixedColumnScrollPane extends JScrollPane
        public FixedColumnScrollPane(JTable main, int fixedColumns)
            super( main );
            //  Use the table to create a new table sharing
            //  the DataModel and ListSelectionModel
            JTable fixed = new JTable( main.getModel() );
            fixed.setSelectionModel( main.getSelectionModel() );
            fixed.getTableHeader().setReorderingAllowed( false );
            fixed.getTableHeader().setResizingAllowed( false );
            fixed.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
            main.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
            //  Remove the fixed columns from the main table
            for (int i = 0; i < fixedColumns; i++)
                TableColumnModel columnModel = main.getColumnModel();
                columnModel.removeColumn( columnModel.getColumn( 0 ) );
            //  Remove the non-fixed columns from the fixed table
            while (fixed.getColumnCount() > fixedColumns)
                TableColumnModel columnModel = fixed.getColumnModel();
                columnModel.removeColumn( columnModel.getColumn( fixedColumns ) );
            //  Add the fixed table to the scroll pane
            fixed.setPreferredScrollableViewportSize(fixed.getPreferredSize());
            setRowHeaderView( fixed );
            setCorner(JScrollPane.UPPER_LEFT_CORNER, fixed.getTableHeader());
        public static void main(String[] args)
            //  Build your table normally
            JTable table = new JTable(10, 8);
            table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            JScrollPane scrollPane= new FixedColumnScrollPane(table, 2 );
            JFrame frame = new JFrame("Table Fixed Column Demo");
            frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            frame.getContentPane().add( scrollPane );
            frame.setSize(400, 300);
            frame.setVisible(true);
    }

  • JDBC locking access db

    i can create the table from jframe. i can open the program and instantly insert records, but if i insert a table, then try and insert records i get sqlexception error saying database is locked by othe process and I DON'T have Access open or another instance of this program. but it does seem to write the new records. any help would be great. fully runnable code presuming you setup Coffee DSN. it locks on line 180 which is part of the tableExistsCreateNew method where i try and drop the table.
    mike
    screen output.
    A Table already exists with data
    Old table was deleted.
    New table was created successfully
    Table has data records, they will be deleted
    An empty table exists
    Error in creatingtable after dropping.Records were created successfully
    import java.io.*;
    import java.net.*;
    import java.sql.*;
    import javax.swing.JTextPane;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    * CoffeeDBAdmin.java
    * Created on July 20, 2004, 1:33 PM
    * @author Participant5
    public class CoffeeDBAdmin extends javax.swing.JFrame {
    /** Creates new form CoffeeDBAdmin */
    Connection conn;
    String message;
    public CoffeeDBAdmin() {
    initComponents();
    createConnection();
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    private void initComponents() {//GEN-BEGIN:initComponents
    jTextPane1 = new javax.swing.JTextPane();
    jMenuBar1 = new javax.swing.JMenuBar();
    MenuDatabase = new javax.swing.JMenu();
    CreateTable = new javax.swing.JMenuItem();
    Insert = new javax.swing.JMenuItem();
    Retrieve = new javax.swing.JMenuItem();
    Exit = new javax.swing.JMenuItem();
    setTitle("CoffeeDBAdmin");
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent evt) {
    exitForm(evt);
    jTextPane1.setMinimumSize(new java.awt.Dimension(375, 200));
    jTextPane1.setPreferredSize(new java.awt.Dimension(375, 200));
    getContentPane().add(jTextPane1, java.awt.BorderLayout.CENTER);
    MenuDatabase.setText("Database");
    MenuDatabase.setActionCommand("MenuDatabase");
    CreateTable.setText("Create Table");
    CreateTable.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseReleased(java.awt.event.MouseEvent evt) {
    CreateTableMouseReleased(evt);
    MenuDatabase.add(CreateTable);
    Insert.setText("Insert");
    Insert.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseReleased(java.awt.event.MouseEvent evt) {
    InsertMouseReleased(evt);
    MenuDatabase.add(Insert);
    Retrieve.setText("Retrieve");
    Retrieve.setActionCommand("Retrieve");
    Retrieve.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseReleased(java.awt.event.MouseEvent evt) {
    RetrieveMouseReleased(evt);
    MenuDatabase.add(Retrieve);
    Exit.setText("Exit");
    Exit.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseReleased(java.awt.event.MouseEvent evt) {
    ExitMouseReleased(evt);
    MenuDatabase.add(Exit);
    jMenuBar1.add(MenuDatabase);
    setJMenuBar(jMenuBar1);
    pack();
    }//GEN-END:initComponents
    private void ExitMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ExitMouseReleased
    // TODO add your handling code here:
    exitRoutine();
    }//GEN-LAST:event_ExitMouseReleased
    public void createConnection()
    try{
    //load JDBC ODBC driver
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    //setup the connection
    String url = "jdbc:odbc:Coffee";
    conn = DriverManager.getConnection
    (url, "myLogin", "myPassword");
    catch (Exception e)
    message = "DSN Error.";
    JOptionPane.showInternalMessageDialog(jMenuBar1,
    message);
    //e.printStackTrace();
    public void createTable()
    try
    Statement stmt = conn.createStatement();
    //jTextPane1.setText(null);
    //stmt.executeUpdate("DROP TABLE COFFEES");
    stmt.executeUpdate("CREATE TABLE COFFEES " +
    "(COFFEE_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, " +
    "SALES INTEGER, TOTAL INTEGER)");
    System.out.println();
    //jTextPane1.setText(null);
    stmt.close();
    catch(NullPointerException npe)
    //we are gonna leave this empty because if you try and call an update
    //without having a database, this exception will occur. it is not
    //necessary to throw this exception as the program print a message and
    //will exit if there is a database problem.
    message = "Database Error";
    JOptionPane.showInternalMessageDialog(jMenuBar1,
    message);
    catch (SQLException tableExists)
    //System.out.println("Table already exists");
    this.tableExistsCreateNew();
    public void tableExistsCreateNew()
    try{
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT Coffee_Name, " +
    "Price FROM COFFEES");
    if((rs.next() == true))
    message = "A Table already exists with data\n";
    else
    message = "An empty table exists\n";
    rs = stmt.executeQuery("SELECT Coffee_Name, Price " +
    "FROM COFFEES");
    jTextPane1.setText(jTextPane1.getText() + "\n" + message);
    stmt.executeUpdate("DROP TABLE COFFEES");
    jTextPane1.setText(jTextPane1.getText() +
    "Old table was deleted.\n");
    stmt.executeUpdate("CREATE TABLE COFFEES " +
    "(COFFEE_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, " +
    "SALES INTEGER, TOTAL INTEGER)");
    jTextPane1.setText(jTextPane1.getText() +
    "New table was created successfully\n");
    //this.createRecords();
    stmt.close();
    //rs.close();
    catch(NullPointerException npe)
    //we are gonna leave this empty because if you try and call an update
    //without having a database, this exception will occur. it is not
    //necessary to throw this exception as the program print a message and
    //will exit if there is a database problem.
    jTextPane1.setText(jTextPane1.getText() + "\nDatabase Error.");
    JOptionPane.showInternalMessageDialog(jMenuBar1,"Database" +
    " Error");
    catch(Exception e)
    System.out.println("\nerror in creating table after dropping\n");
    e.printStackTrace();
    //System.exit(0);
    jTextPane1.setText(jTextPane1.getText() + "\nError in creating" +
    "table after dropping.\n");
    JOptionPane.showInternalMessageDialog(jMenuBar1,
    "Error in creating table after dropping.\n");
    public void createRecords()
    try
    { Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT " +
    "Coffee_Name, Price " + "FROM COFFEES");
    if(rs.next() == false)
    jTextPane1.setText(jTextPane1.getText() +
    "\nTable has data records, they will be " +
    " deleted\n\n");
    //stmt.executeUpdate("DROP TABLE COFFEES");
    tableExistsCreateNew();
    stmt.executeUpdate("INSERT INTO COFFEES " +
    "(Coffee_Name, SUP_ID, Price) " +
    "VALUES ('Colombian', 101, 7.99)");
    stmt.executeUpdate("INSERT INTO COFFEES "+
    "(Coffee_Name, SUP_ID, Price) " +
    "VALUES ('French_Roast', 49, 8.99)");
    jTextPane1.setText(jTextPane1.getText() + "Records" +
    " were created successfully\n");
    //rs.close();
    stmt.close();
    catch (Exception e)
    //System.out.println("Error in creating records");
    //e.printStackTrace();
    //System.exit(0);
    message = "The Table you requested does not exist.";
    JOptionPane.showInternalMessageDialog(jMenuBar1,message);
    public void printRecords()
    try
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT Coffee_Name, Price " +
    "FROM COFFEES");
    jTextPane1.setText("Coffee Prices\n");
    //System.out.println("Coffee Prices");
    while(rs.next())
    jTextPane1.setText((jTextPane1.getText() + rs.getString(1)
    + " " + rs.getDouble(2) + "\n" ));
    // System.out.println(rs.getString(1) + " " +
    // rs.getDouble(2) + "\n" );
    //rs.close();
    stmt.close();
    //conn.close();
    catch(NullPointerException npe)
    //we are gonna leave this empty because if you try and call an update
    //without having a database, this exception will occur. it is not
    //necessary to throw this exception as the program print a message and
    //will exit if there is a database problem.
    message = "Database Error";
    jTextPane1.setText(jTextPane1.getText() + "\n" +
    message);
    JOptionPane.showInternalMessageDialog(jMenuBar1,"You " +
    "cannot retrieve" + "records from a null or " +
    "uncreated table");
    //System.exit(0);
    catch (Exception e)
    //message = "Error in printing records";
    jTextPane1.setText(jTextPane1.getText() +"\n" +
    message);
    //System.exit(0);
    e.printStackTrace();
    //JOptionPane.showInternalMessageDialog(jMenuBar1,"You cannot retrieve" +
    //"records from a null or uncreated table");
    public void exitRoutine()
    try{
    conn.close();
    dispose();
    System.exit(0);
    catch (Exception e)
    message = "error closing connection";
    JOptionPane.showInternalMessageDialog(jMenuBar1,
    message);
    //e.printStackTrace();
    private void RetrieveMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RetrieveMouseReleased
    // TODO add your handling code here:
    printRecords();
    }//GEN-LAST:event_RetrieveMouseReleased
    private void InsertMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_InsertMouseReleased
    // TODO add your handling code here:
    createRecords();
    }//GEN-LAST:event_InsertMouseReleased
    private void CreateTableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CreateTableMouseReleased
    // TODO add your handling code here:
    createTable();
    }//GEN-LAST:event_CreateTableMouseReleased
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
    dispose();
    System.exit(0);
    }//GEN-LAST:event_exitForm
    * @param args the command line arguments
    public static void main(String args[]) {
    new CoffeeDBAdmin().show();
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem CreateTable;
    private javax.swing.JMenuItem Exit;
    private javax.swing.JMenuItem Insert;
    private javax.swing.JMenu MenuDatabase;
    private javax.swing.JMenuItem Retrieve;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration//GEN-END:variables

    Are you releasing your connections appropriately?

  • Swing locks up during event handling of a simple button... bug or feature?

    I have the following code:
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JToolBar;
    import javax.swing.SwingUtilities;
    public class Test extends JFrame {
         private static final long serialVersionUID = 1L;
         private JButton button;
         public static void main(String[] args)
              SwingUtilities.invokeLater(new Runnable(){public void run(){new Test();}});
         public Test()
              setSize(200,00);
              setLayout(new BorderLayout());
              JToolBar toolbar = new JToolBar();
              button = new JButton("button");
              button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { button.setEnabled(false);}});
              toolbar.add(button);
              getContentPane().add(toolbar, BorderLayout.SOUTH);
              JPanel panel = new JPanel();
              panel.setPreferredSize(new Dimension(200,10000));
              for(int i=0;i<10000; i++) { panel.add(new JLabel(""+(Math.random()*1000))); }
              JScrollPane scrollpane = new JScrollPane();
              scrollpane.getViewport().add(panel);
              scrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
              scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
              scrollpane.setPreferredSize(getSize());
              scrollpane.setSize(getSize());
              getContentPane().add(scrollpane, BorderLayout.CENTER);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setLocationRelativeTo(null);
              setVisible(true);
              pack();
    }This code is lethal to swing: when pressing the button, for no identifiable reason the entire UI will lock up, even though all the event handler is doing is setting the button's "enabled" property to false. The more content is located in the panel, the longer this locking takes (set -Xmx1024M and the label loop to 1000000 items, then enjoy timing how long it takes swing to realise that all it has to do is disable the button...)
    Does anyone here know of how to bypass this behaviour (and if so, how?), or is it something disastrous that cannot be coded around because it's inherent Swing behaviour?
    I tried putting the setEnabled(false) call in a WorkerThread... that does nothing. It feels very much like somehow all components are locked, while the entire UI is revalidated, but timing revalidation shows that the panel revalidates in less than 50ms, after which Swing's stalled for no reason that I can identify.
    Bug? Feature?
    how do I make it stop doing this =(
    - Mike

    However, if you replace "setEnabled(false)" with "setForeground(Color.red)") the change is instant,I added a second button to the toolbar and invoked setEnabled(true) on the first button and the change is instant as well. I was just looking at the Component code to see the difference between the two. There are a couple of differences:
        public void setEnabled(boolean b) {
            enable(b);
         * @deprecated As of JDK version 1.1,
         * replaced by <code>setEnabled(boolean)</code>.
        @Deprecated
        public void enable() {
            if (!enabled) {
                synchronized (getTreeLock()) {
                    enabled = true;
                    ComponentPeer peer = this.peer;
                    if (peer != null) {
                        peer.enable();
                        if (visible) {
                            updateCursorImmediately();
                if (accessibleContext != null) {
                    accessibleContext.firePropertyChange(
                        AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
                        null, AccessibleState.ENABLED);
         * @deprecated As of JDK version 1.1,
         * replaced by <code>setEnabled(boolean)</code>.
        @Deprecated
        public void enable(boolean b) {
            if (b) {
                enable();
            } else {
                disable();
         * @deprecated As of JDK version 1.1,
         * replaced by <code>setEnabled(boolean)</code>.
        @Deprecated
        public void disable() {
            if (enabled) {
                KeyboardFocusManager.clearMostRecentFocusOwner(this);
                synchronized (getTreeLock()) {
                    enabled = false;
                    if (isFocusOwner()) {
                        // Don't clear the global focus owner. If transferFocus
                        // fails, we want the focus to stay on the disabled
                        // Component so that keyboard traversal, et. al. still
                        // makes sense to the user.
                        autoTransferFocus(false);
                    ComponentPeer peer = this.peer;
                    if (peer != null) {
                        peer.disable();
                        if (visible) {
                            updateCursorImmediately();
                if (accessibleContext != null) {
                    accessibleContext.firePropertyChange(
                        AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
                        null, AccessibleState.ENABLED);
        }The main difference appears to be with the KeyboardFocusManager. So instead of using a toolbar, I changed it to a JPanel (so the buttons are focusable). I then notice the same lag when I try to tab between the two buttons. So the problem is with the focus manager, not the setEnabled() method.

  • How to get info who is locking a specific row in the RDBMS 9i?

    Hi,
    could some one please helop me with this? I would like to know the Oracle user name of the user who is locking a specific row in my table. I can display all locking requests with the following SQL statements. What I could not igure out how to find the rownum that is being locked by others?
    SELECT *
    FROM v$lock lk, v$session s , DBA_OBJECTS ao, wf_users wu
    WHERE lk.lmode > 1
    AND s.username IS NOT NULL
    AND lk.SID = s.SID
    AND ao.OBJECT_ID(+) = lk.id1
    AND s.username = wu.NAME(+)
    AND ao.owner = USER
    AND ao.object_name = 'BWF_IKTATASI_ADATLAPOK';
    Thank you in advance,
    Tamas Szecsy

    I'm not sure what's happening with your app. I wrote on up to see if it could handle the CTRL-C. Seems to work fine. Do you have any other JMenuItems with the same accelerator?
    import java.awt.event.*;
    import javax.swing.*;
    public class Copy extends JFrame {
         public Copy() {
              this.initMenuBar();
              this.setSize(400, 300);
              this.setVisible(true);
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         private void initMenuBar() {
              JMenuBar menubar = new JMenuBar();
              JMenu edit = new JMenu("Edit");
              JMenuItem copy = new JMenuItem(new CopyAction("Copy"));
              edit.setMnemonic(KeyEvent.VK_E);
              copy.setMnemonic(KeyEvent.VK_C);
              copy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK));
              edit.add(copy);
              menubar.add(edit);
              this.setJMenuBar(menubar);
         public static void main(String[] args) {
              new Copy();
         private class CopyAction extends AbstractAction {
              public CopyAction(String label) {
                   super(label);
              public void actionPerformed(ActionEvent e) {
                   System.out.println("Action Performed.");
    }

  • How can i prevent the error "mailbox locked by a pop 3 session"

    how do i prevent the repeated error " mailbox locked by a pop 3 session!"

    lol i think he was talking about formating your messages on the forum.
    look at an example that i just created hope it helps. If not then read up on the GUI chapter of your java book.
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JTextField;
    import java.awt.BorderLayout;
    public class ButtonTest{
        public static void main(String args []){
            JFrame frame = new JFrame();
            JPanel panel = new JPanel();
            final JTextField textA = new JTextField(10);
            final JTextField textB = new JTextField(10);
            JButton button = new JButton("Perform Action");
            class Listener implements ActionListener{
                public void actionPerformed(ActionEvent e){
                    if(!textA.getText().equals("") && !textB.getText().equals("")){
                        System.out.println(textA.getText()+" "+textB.getText());
           ActionListener listener = new Listener();
            button.addActionListener(listener);
            panel.add(textA);
            panel.add(textB);
            panel.add(button);
            frame.getContentPane().add(panel,BorderLayout.SOUTH);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.show();
    }

  • Center Frame & Lock in Minimum Size

    Before setting the main frame visible, many (if not most) Swing applications need to center the frame and lock in a minimum size. These are basic, fundamental steps, but currently they require writing a fair amount of tedious code. This situation could be improved with a couple of convenience methods.
    For example:   JFrame frame = new JFame();
       //add UI controls
       frame.pack();
       frame.center();
       frame.setMinimumSize(frame.getCurrentSize()); Any idea why these (or similar) methods are not included in Java? It sure would clean up the top level Swing class in many applications.
    - Dem

    This situation could be improved with a couple of convenience methods.So create a class called MyFrame and write your own. Everybody has there own idea of whats important and whats not. Thats why you have the ability to extend classes --- to add your own functionality.
    have you tried:
    frame.setLocationRelativeTo( null );
    If your looking for a way to control the minimum size then use add a ComponentListener to the frame. Examples have been posted in the forum.

  • Pcanywhere swing lock

    The following simple code produces a lock if I start it via PC-Anywhere(Version 10.5) on Windows2000-Server with the JDK-Version:
    java version "1.4.1"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
    Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)
    import javax.swing.*;
    public class TestFrame {
    public static void main(String[] args) {
    JFrame frame = new JFrame("HelloWorldSwing");
    final JLabel label = new JLabel("Hello World");
    frame.getContentPane().add(label);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
    If PC-Anywhere does not run on the server and I start it directly at the server, it works.
    It also works if I use this JDK-Version (and start it via PC-Anywhere):
    java version "1.3.0"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
    Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
    I debugged it with a remote-Debugger and in fact there was a deadlock at
    java.awt.Container.preferredSize(Container.java:1175)
    as you also see in the thread dump below.
    It seems to be bug of the JDK and/or PC-Anywhere. If you know something about it, thanx for your comment.
    Full thread dump Java HotSpot(TM) Client VM (1.4.1-b21 mixed mode):
    "AWT-EventQueue-0" prio=7 tid=0x0ACDC880 nid=0x8e4 runnable [af5f000..af5fd88]
    at sun.awt.windows.Win32SurfaceData.initOps(Native Method)
    at sun.awt.windows.Win32SurfaceData.<init>(Win32SurfaceData.java:432)
    at sun.awt.windows.Win32SurfaceData.createData(Win32SurfaceData.java:311
    at sun.awt.windows.WComponentPeer.replaceSurfaceData(WComponentPeer.java
    :321)
    - locked <02A5FB88> (a sun.awt.windows.WFramePeer)
    - locked <02EFC8A8> (a java.awt.Component$AWTTreeLock)
    at sun.awt.windows.WComponentPeer$2.run(WComponentPeer.java:334)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:448)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:197)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
    "Java2D Disposer" daemon prio=10 tid=0x0ACDC1A8 nid=0xea4 in Object.wait() [af1f
    000..af1fd88]
    at java.lang.Object.wait(Native Method)
    - waiting on <02A60A50> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
    - locked <02A60A50> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
    at sun.java2d.Disposer.run(Disposer.java:97)
    at java.lang.Thread.run(Thread.java:536)
    "AWT-Windows" daemon prio=7 tid=0x0ACD56A0 nid=0xb20 runnable [aecf000..aecfd88]
    at sun.awt.windows.WToolkit.eventLoop(Native Method)
    at sun.awt.windows.WToolkit.run(WToolkit.java:253)
    at java.lang.Thread.run(Thread.java:536)
    "AWT-Shutdown" prio=5 tid=0x0ACD5388 nid=0xc1c in Object.wait() [ae8f000..ae8fd8
    8]
    at java.lang.Object.wait(Native Method)
    - waiting on <02A77AF8> (a java.lang.Object)
    at java.lang.Object.wait(Object.java:426)
    at sun.awt.AWTAutoShutdown.run(AWTAutoShutdown.java:259)
    - locked <02A77AF8> (a java.lang.Object)
    at java.lang.Thread.run(Thread.java:536)
    "Signal Dispatcher" daemon prio=10 tid=0x008F84D0 nid=0xbc0 waiting on condition
    [0..0]
    "Finalizer" daemon prio=9 tid=0x008F7B18 nid=0xd04 in Object.wait() [ab4f000..ab
    4fd88]
    at java.lang.Object.wait(Native Method)
    - waiting on <02EFC408> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
    - locked <02EFC408> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
    at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)
    "Reference Handler" daemon prio=10 tid=0x008F6690 nid=0xc14 in Object.wait() [ab
    0f000..ab0fd88]
    at java.lang.Object.wait(Native Method)
    - waiting on <02EFC470> (a java.lang.ref.Reference$Lock)
    at java.lang.Object.wait(Object.java:426)
    at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:113)
    - locked <02EFC470> (a java.lang.ref.Reference$Lock)
    "main" prio=5 tid=0x00234CF0 nid=0x850 waiting for monitor entry [6f000..6fc3c]
    at java.awt.Container.preferredSize(Container.java:1175)
    - waiting to lock <02EFC8A8> (a java.awt.Component$AWTTreeLock)
    at java.awt.Container.getPreferredSize(Container.java:1159)
    at java.awt.Window.pack(Window.java:430)
    at test.TestFrame.main(TestFrame.java:44)
    "VM Thread" prio=5 tid=0x008F5458 nid=0x87c runnable
    "VM Periodic Task Thread" prio=10 tid=0x0023F158 nid=0xc8c waiting on condition
    "Suspend Checker Thread" prio=10 tid=0x0023FAB8 nid=0xc88 runnable

    Hi there
    Have you found any solution for that ??
    I am having the same problem too.
    Please help if you have solved it.
    best regards
    Edmond

  • Converting JFrame app to JSP?

    hi
    I have a JFrame application that accesses a database and I wanted to make it web enabled using JSP.
    Is there an IDE or some way I can do this in an easier way by making use of the JFrame application I already have?
    thanks

    Applets can be so bothersome. To this day, every applet project I have done has had issues. There have been painting issues with Internet Explorer, issues with firewalls, issues with clients not being able to open up the sandbox restrictions, issues with Internet explorer locking up, issues with signed applets, issues with browser plugins...you name it. Trust me, its better to stay away from applets because of the various issues that inevitably arise. Your new JSP/Servlet design, if done using the Model-View-Controller design pattern, will work so much better.
    Hopefully you have a good OO design in your JFrame app. That is, hopefully you put the code to connect to the database, etc. into separate classes. Then, you could reuse a lot of your classes on the serverside to retrieve the data, etc. If I were you, I would scrap the JFrame to JSP idea. Just design a user interface in html (use a tool if necessary) and then add your JSP hooks. Try to keep the java out of the JSP and the HTML out of the Servlets; use java beans or regular java classes while putting a small amount of scriptlets, expressions, and JSP tags into your JSP page. You should be able to reuse much of your non GUI code from your JFrame app.
    Lastly, you will probably find it good design to use a Contol Servlet. That is, have one servlet process all requests and then forward to the correct page. For an example, examine the apache struts framework: http://jakarta.apache.org/struts/
    To summarize. Your JFrame was really a client-server app. Now, you are moving into the web-based application and so you have to take it to the next level. You know, have a multitiered environment with EJB's or the like in the middle tier and the database on the last tier.
    I hope all this babble was any help.

  • JPasswordField locking issue in linux

    Hi,
    password field is working good if its alone in the panel/frame. if added textfield for username before password field, password field is locking and its never allowing to enter the data. this issue is in linux.* the same code works well in windows platform. is this a bug? i am using latest jre though....
    public class test3 extends JFrame implements ActionListener
        JTextField txtUserName=new JTextField(10);
        JPasswordField pwd = new JPasswordField(10);
        public test3()
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             getContentPane().setLayout(new GridLayout(2,1));
             getContentPane().add(txtUserName);
         getContentPane().add(pwd);
         txtUserName.addActionListener(this);
         pwd.addActionListener(this);
         pack();
         setVisible(true);
        public void actionPerformed(ActionEvent e)
             System.out.println("UserName=" + txtUserName.getText());
             System.out.println("Password=" + pwd.getText());
        public static void main(String arg[])
             new test3();
    }My environment...
    [root@uma ~]# java -version
    java version "1.6.0_13"
    Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
    Java HotSpot(TM) Server VM (build 11.3-b02, mixed mode)
    [root@uma ~]#
    [root@uma ~]# uname -a
    Linux uma 2.6.18-92.1.13.el5PAE #1 SMP Wed Sep 24 20:07:49 EDT 2008 i686 i686 i386 GNU/Linux
    [root@uma ~]#
    [root@uma ~]# cat /etc/redhat-release
    CentOS release 5.2 (Final)

    Note: This thread was originally posted in the [Java Programming|http://forums.sun.com/forum.jspa?forumID=31] forum, but moved to this forum for closer topic alignment.

Maybe you are looking for

  • User Exit/BAdI for transaction ME22N - Release status of PO

    Dear All, Requirement: Irrespective of any change to a PO having its release indicator set to approved, the release indicator must not get updated. As of now, editing a PO (using ME22N) leads to the updation of release group, release strategy and rel

  • How to do equivalent of Mainframe batch jobs in Oracle

    Hi Everybody , We are considering to move our application from mainframe to Oracle , our present day application relies heavily on mainframe batch jobs for report generation and other purposes, I was wondering what are the similar batch options we ha

  • Unite ruined my phone and I want to remove it forever.. please help me???

    I downloaded this "crap" on my phone, could never register an email on it... please don't think I'm a retard, i've never had any trouble being technical about anything before... but this is absolutely the most frustrating thing I've ever had to deal

  • Cannot Ingest RED Footage in Prelude

    I'm trying to ingest RED Epic footage in a variety of formats, but Prelude is unable to pull any of it in. The error message reported in the Events panel is "Import task - import file: "{path\filename}.R3D" failed. Reason: Import XMP failed!" I'm run

  • Tax Apportionment for Cross-Company Code

    how can 'business area'  be inherited from the source FI documents which are generated by cross-company transaction?.for example: company code D/C account business area amount 1000 D expense 1000 1000 1000 D tax 234 1000 C vendor 1000 2234 1000 D cle