I have a jtable in second jframe (calisanEkrani) and I want those table informations printed to the third jframe (guvenliksorusturmaformu). I got the printing part and I made a button to open the third jframe but I can't focus (click or edit anything) and close the frame without closing the second.
How can I make the third jframe appear focused, editable (jtextfield) and when closed, comes back to the second frame?
This is the button action in calisanEkrani:
private void formcikartActionPerformed(java.awt.event.ActionEvent evt) {
guvenliksorusturmaformu gf = new guvenliksorusturmaformu();
guvenliksorusturmaformu.form_adsoyad.setText(this.ad_alani.getText());
guvenliksorusturmaformu.form_departman.setText(this.dept_alani.getText());
guvenliksorusturmaformu.form_maas.setText(this.maas_alani.getText());
gf.setVisible(true);
}
I want the guvenliksorusturmaformu frame on top and clickable. I can't even press 'X' to close it. It makes windows error sound and flashes but I can still play with the calisanEkrani (second jframe).
(Not very good at English so basic explanation or just the code will be good)
Related
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
createbox();
heroname.setText("Name of the hero: " + CharName);
}
});
This is inside a JMenuItem, where if I click it, it creates a createbox which is another frame and panel that allows me to input the character name in a text field.
Everything works as expected (Charname is a static variable that changes within createbox when the user clicks the button "finish" that closes that frame and sets CharName to whatever was inside the text field)
BUT how do I make the main frame/panel "sleep" while createbox() is doing its thing?
Basically: how can I get a Thread.sleep(x) to work so it ONLY updates the label heroname once createbox() is closed again (only when closing it via ActionListener on the finish button of course)
Or, if possible: How do I change the label of another frame with a press of a button?
I cannot change heroname within createbox() and if I try to make it sleep, the whole program is sleeping and doesn't open the 2nd frame.
You should keep the instance of other frame at createbox frame.
finish button Just should hide the createbox frame.
since you have the instance of other frame, when you click on finish, you can Just call the changeLabel method of instance.
This is a solution but maybe you can find a better one.
I have three frames, let's call them Frame Welcome, Frame Main, Frame Sub. They're all in separate classes.
Frame Welcome has a button that makes Frame Main visible when clicked.
Frame Main has a button that makes Sub pop up when clicked (sort of a dialog box yeah but it has graphical design so I figured out to just put it in a separate frame, though I'm considering JPanel but I'm not sure how to do that: how to make it pop up when it's in a JPanel, possibly setVisible but I havent tried that yet so I might try it later), but there is also a button in Frame Sub which when clicked, should make Frame Main and Frame Sub invisible and display Frame Welcome only instead.
At the moment, I have a code for making Sub disappear and make Welcome appear, but I can't figure out how to make Main invisible too.
public void actionPerformed (ActionEvent e)
{
if (e.getSource() == btn)
{
FrameWelcome fw = new FrameWelcome();
setVisible(false);
fw.setVisible(true);
}
}
This makes the Frame Sub invisible and the Frame Welcome visible, but how will I make Frame Main invisible too (Sub is SORT OF inside Main, because it's displayed when a button is clicked in Main)? This isn't exactly my code but I'm not sure which parts to post so yeah
When my program launches, a window (aka "StartWindow") opens that has 3 options: New Game/Load Game/Exit. When New Game or Load Game is clicked (and after some input), the game window (aka "GameWindow") will open so the user can play.
When the GameWindow opens, I would like to have the StartWindow close. And when the GameWindow closes, the StartWindow will open until the actual "EXIT" button is clicked.
Is there a way to do this? Right now, the only way I can achieve something similar to this is having a boolean called "gameRunning". When this is true, the buttons on StartWindow will have no action when clicked. Opposite when false.
For example purposes, suppose that each window has 3 buttons, a text field, and nothing else.
Use setVisible(false) method on parent before opening any child window. When child window closes call setVisible(true). It will solve your problem
I've been struggling with some problem while creating my app based on Swing. I have a main JFrame which consists of:
JMenu
JPanel containing a JButton and a JLabel
JButton is linked with ActionListener. Clicking JMenu (MenuListener) brings up a JDialog with some form. The problem is, when the JDialog is closed (it doesn't make difference whether I do it with dispose() or rather showVisible(false)) I need to click the JButton two times before it triggers for the first time. From now it normally works with one click.
Every time the JDialog is in front, the problem appears.
PS. The JDialog is set to be modal, with JFrame as parent.
It sounds like a focus issue.
The first click restores focus to the app and the second clicks the button. Typically, I have seen this when the JDialog has the wrong parent and focus can not be returned.
Thank you for your answers.
I have considered posting some code, but it involves 4 classes so will be quite long.
I have also tried things with focus before, but nothing helped. What is interesting: if I display the JDialog by new myDialog.showVisible(true) it behaves like I've described. But if I use construction like this:
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new JDialog.setVisible(true);
}
});
it closes normally and parent frame doesn't need to be clicked before responding, but on the other hand the displayed Dialog needs so. Additonally, what I do not understand, after opening the Dialog cursor is placed in the text field and I can write normally, but to click some button on it I must click once on the Dialog, only second and next clicks behave like I want to.
PS. Closing the dialog like in the second included example changes nothing.
I have an applet which has two buttons on it:
When we click Button1 a Frame is opened.
When we click Button2 a Dialog (which is a child the new frame) is presented.
Now suppose if when we click on Button1 then the new frame that is opened is now positioned behind my applet and not completely aligned with it (not minimized)
Now, when I press Button2 the Dialog that pops up is in front of my applet, but when I click on the header of the dialog, then both the applet and frame are brought forward (they both get displayed simultaneously).
So I basically want to have just the applet behind the dialog whenever it is clicked (leaving the Frame in the background)
Add a frame.setVisible(false); in Button2's ActionListener.