JTextField Java applet not available after JDialog on Ubuntu

I have 2 problems with java on Ubuntu:

  • JTextField becomes inaccessible, and you cannot type anything in it. To play, you need to click on the label ("Click this label"), it will open my advanced JDialog. After closing the Cancel button, the JTextField becomes unavailable. The problem is that it does not happen all the time. I think about 1 in 10 attempts. When this happens, you need to click again in the browser window or open the dialog again.

  • The second problem is that when ubuntu opens JDialog, it creates another process that appears in the application bar on the left. You can click somewhere on the applet in the dialog box, and this dialog box will be displayed in the browser, even if it is considered modal and should be on top.

Did anyone get similar errors with ubuntu and knew how to fix it. Everything works fine in windows. We use ubuntu-12.04-desktop and java 1.6.0_34-b04. It has been tested in firefox 11.0 and Google chrome (the newest, I think)

Here is my code TestApplet.java class:

import java.awt.FlowLayout; import java.awt.Frame; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JApplet; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.SwingUtilities; import client.utilities.GUIUtilities; @SuppressWarnings("serial") public class TestApplet extends JApplet { public void init() { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { JApplet applet = TestApplet.this; applet.setLayout(new FlowLayout()); JTextField ts = new JTextField("Test text"); ts.setColumns(10); applet.add(ts); applet.add(getCallCalendarButton(ts)); } }); } catch (Exception e) { System.err.println(e.getCause()); } } private JLabel callCalendarButton; private MyDialog aDialog; protected JLabel getCallCalendarButton(final JComponent cmp) { if (callCalendarButton == null) { callCalendarButton = new JLabel("Click this label!!"); callCalendarButton.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (callCalendarButton.isEnabled()) { Frame parentFrame = null; if (parentFrame == null) parentFrame = GUIUtilities.getParentFrame(cmp); System.out.println(parentFrame); aDialog = new MyDialog(parentFrame, cmp); aDialog.setVisible(true); System.out.println("qwewqe"); cmp.requestFocusInWindow(); } } }); } return callCalendarButton; } } 

And here is the extended JDialog class (MyDialog.java):

  import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JPanel; import javax.swing.SwingUtilities; @SuppressWarnings("serial") public class MyDialog extends JDialog { private JButton okButton; private JButton cancelButton; private JComponent owner; private int WIDTH = 230; private int HEIGHT = 230; Frame parent; public MyDialog(Frame parent, JComponent owner) { super(parent); this.parent = parent; this.owner = owner; okButton = new JButton("OK"); okButton.setMnemonic('O'); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { MyDialog.this.setVisible(false); MyDialog.this.dispose(); } }); cancelButton = new JButton("Cancel"); cancelButton.setMnemonic('C'); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { MyDialog.this.setVisible(false); } }); this.setLayout(new BorderLayout()); JPanel bottomPanel = new JPanel(); bottomPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); bottomPanel.add(okButton); bottomPanel.add(cancelButton); this.add(bottomPanel, BorderLayout.SOUTH); this.setModal(true); this.setBounds(100, 100, WIDTH, HEIGHT); // this.addComponentListener(new ComponentAdapter(){ @Override public void componentHidden(ComponentEvent e){ SwingUtilities.invokeLater(new Runnable(){ @Override public void run(){ MyDialog.this.owner.requestFocusInWindow(); //MyDialog.this.parent.toFront(); //MyDialog.this.parent.requestFocusInWindow(); } }); } }); } } 

To use this html to run the applet:

  <html> <body> <Applet Code="TestApplet.class" width="200" height="100" > </Applet> </body> </html> 
+2
java ubuntu swing jdialog jtextfield
Sep 11
source share

No one has answered this question yet.

See similar questions:

8
Focus issues with java7 modal dialogs on mac osx

or similar:

2956
What is the difference between public, secure, batch, and private in Java?
2108
How can I name one constructor from another in Java?
1541
How to break a string in Java
eleven
How to change runtime language in java swing
6
Create a validation properties window by clicking the JDialog button
3
JPanel added but not showing "in time"
one
problem setting scrollpane for canvas
0
Work with the Java community using streaming
0
How to add JTextField
0
How to enter information into sql database from JTextField?



All Articles