jframe

JScrollPane doesn't work for my JPanel

不打扰是莪最后的温柔 提交于 2019-12-05 15:15:27
first of all I must say that I have checked these questions and didn't find my answer : 1 , 2 , 3 , 4 , 5 , 6 , 7 and many other questions like so also I have checked these tutorials and examples: 1 , 9 , 10 , 11 and many other sites. but I couldn't fix my problem. and this is the simple kind of my code: public class Question extends JFrame { public Question() { Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); setLayout(new BorderLayout()); setSize(d.width, d.height); setResizable(false); setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel panel = new JPanel(); panel.setPreferredSize(new

How to make “Enter” Key Behave like Submit on a JFrame

≯℡__Kan透↙ 提交于 2019-12-05 13:34:37
I'm Building a Client/Server application. and I want to to make it easy for the user at the Authentication Frame. I want to know how to make enter -key submits the login and password to the Database (Fires the Action) ? trashgod One convenient approach relies on setDefaultButton() , shown in this example and mentioned in How to Use Key Bindings . JFrame f = new JFrame("Example"); Action accept = new AbstractAction("Accept") { @Override public void actionPerformed(ActionEvent e) { // handle accept } }; private JButton b = new JButton(accept); ... f.getRootPane().setDefaultButton(b); Add an

How do I disable a JPanel so that it can't change size in Java

谁说我不能喝 提交于 2019-12-05 09:02:00
I have several JPanels in a layout and whenever I change the size of the JFrame manually with my mouse, it stretches the JPanels and makes it look messy. Is there a way to disable this? JPanel is not resizable by the user. If you are referring to JFrame, you can use yourFrame.setResizable(false); It's all about the LayoutManager you are using. Some LayoutManagers like BorderLayout always give extra space to children added in the center position. However, north, south, east, and west only allocated the preferred size to them. My favorite LayoutManager is TableLayout which is extremely easy to

How to properly hide a JFrame

穿精又带淫゛_ 提交于 2019-12-05 07:42:07
I have a very simple JFrame window that contains one button: No . In the main function I set setVisible(true); my JFrame and in the No button listener I want to close the window so I set the visibility to false: setVisible(false); and after that I do System.exit(0); in order to prevent possible memory leaks when running the program many times. I have two questions: Do I really need to System.exit(0); in the above case? If I have this JFrame as a popup window, I can't really use System.exit(0); because this will terminate the whole program. So how can I properly close the popup window and stay

Can you make an uncloseable, unleavable, Java application?

霸气de小男生 提交于 2019-12-05 02:05:53
Is there a way to make sure that a user cannot close or leave my Swing application? I've tried to make it fullscreen, but you can still Alt-Tab away from it—and besides, that doesn't work well when you decide to use JOptionPane's dialogs. So, is there any way to make a user use only this one Java program on a device? Edit: Some people wonder about the purpose. The application is supposed to be sorta "embedded" into the handheld device (which runs under Windows), so the users of the device will use it as we intend it to be used—for example, that they won't play Freecells or do something worse

Transparent, click-through, always on top JFrame [closed]

假如想象 提交于 2019-12-05 02:00:26
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . So I currently have a transparent JFrame that you can click through, but I need it to stay on top of all other windows. Let's say you have a browser open, I want the JFrame to stay on top of it but be able to

Adding a new WindowListener to a JFrame

为君一笑 提交于 2019-12-05 01:52:16
问题 mainFrame.addWindowListener(new WindowListener() { @Override public void windowClosing(WindowEvent e) { if (JOptionPane.showConfirmDialog(mainFrame, "Are you sure you want to quit?", "Confirm exit.", JOptionPane.OK_OPTION, 0, new ImageIcon("")) != 0) { return; } System.exit(-1); } @Override public void windowOpened(WindowEvent e) {} @Override public void windowClosed(WindowEvent e) {} @Override public void windowIconified(WindowEvent e) {} @Override public void windowDeiconified(WindowEvent e

How to save edited JTable data to database?

走远了吗. 提交于 2019-12-05 01:45:46
问题 First of all sorry for my poor English. I'll try my best to understand you my problem. All I want is to save the new data whichever user has entered in the JTable whenever Save button will clicked. I am retrieving Student ID, Name in first two columns from database and also i have added current date in third column and Absent/Present as fourth column which is editable. I have following code to retrieve data from database. **Attendance.java** : /* * To change this template, choose Tools |

System.exit(0) vs JFrame.EXIT_ON_CLOSE

[亡魂溺海] 提交于 2019-12-05 01:42:46
Is there any difference between the two. I was reading an article ( http://www.javalobby.org/java/forums/t17933 ) about that you should always use System.exit(0); Currently I use JFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); The article says that even for a Java Swing Application you should add a listener WindowAdapter and and call System.exit() inside its method windowClosing(WindowEvent e) . Is there any difference? Is one method better then the other? If you look at the JFrame code, it does: protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e

Java get JPanel Components

送分小仙女□ 提交于 2019-12-05 00:59:25
I have a JPanel full of JTextFields... for (int i=0; i<maxPoints; i++) { JTextField textField = new JTextField(); points.add(textField); } How do I later get the JTextFields in that JPanel? Like if I want their values with TextField.getText(); Thanks Well bear in mind they didn't get there by them selves ( I think a read some questions about dynamically creating these panels at runtime ) In the answers posted there, someone said you should kept reference to those textfields in an array. That's exactly what you need here: List<JTextField> list = new ArrayLists<JTextField>(); // your code... for