swing

Not all of my JButtons are showing up after I add a dozen of them. What am I doing wrong?

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 22:02:13
问题 I want to add 52 buttons in a JPanel. All with ActionListeners. When I reach a certain amount (13) and run the program, not all of the buttons show up. For example I've added 15 buttons and only 9 or 12 of them show up. Sometimes all of them, but not every time. Here's the code for two of the JButtons: JButton button_one=new JButton(); button_one.setPreferredSize(new Dimension(100,150)); mainpanel.add(button_one); button_one.addActionListener(new ActionListener(){ @Override public void

Buttons overlap or disappear

你。 提交于 2021-01-29 20:24:08
问题 I have an example of a error in my program. I created 4 buttons: 1, 2, 3, 4. Button 2 overlaps button 4, and i just added events for 2 and 4. If I click on Button 2, it will be hidden, and Button 4 will be displayed. And if I click on Button 4, Button 2 will be displayed, and Button 4 will be covered by Button 2 again. As if anything happened, but, when I click on Button 1 or Button 3 after doing the above, Button 4 will be displayed, when I point at it (not click), it will disappear. public

How to accept user input in GUI? - Java [closed]

百般思念 提交于 2021-01-29 18:30:38
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 years ago . Improve this question My program takes an input amount of money and converts it into coins. I need it to have a GUI, and have to make it possible to enter the amount while in the GUI, and then do various things with JButtons and such. I have the program written but I can't figure

How to paint in Java Swing in every concurrent thread?

心不动则不痛 提交于 2021-01-29 18:08:21
问题 The goal of my program is to draw squares from randomly generated points. I want to display a set of squares as soon as they are generated by each thread. However, only one set of squares displays, once all the threads are done running. I have used swinginvoke, and am curious as if there is a problem with repaint() since all the threads reach repaint but don't paint until the final thread is done, and end up overlapping each other. I also don't want the "storedata" variable to be shared

How to disable the ability to highlight in JTextArea

风流意气都作罢 提交于 2021-01-29 16:38:49
问题 I am looking for a way to disable the ability to highlight in the JTextArea. Currently this is my JTextArea: textArea1 = new JTextArea(); textArea1.setBorder(BorderFactory.createLineBorder(Color.black, 1)); DefaultCaret caret = (DefaultCaret) textArea1.getCaret(); // this line and the line below was inspired by a comment found here: https://stackoverflow.com/questions/15623287/how-to-always-scroll-to-bottom-of-text-area caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); textArea1.setEditable

Is there a way to hide the title bar, but keep the buttons in JFrame

蓝咒 提交于 2021-01-29 16:27:13
问题 I was wondering if I could hide the title bar in Java Swing, but keep the maximize, minimize, and close buttons. I've tried adding frame.setUndecorated(true); but it removes the maximize, minimize, and close buttons completely. Here is my code: public Display(String title, int width, int height) { Display.width = width; Display.height = height; Display.absWidth = width; Display.absHeight = height; Display.d = new Dimension(width, height); setProperties(); image = new BufferedImage(width,

How to across JTextField to next JTextField by hit Enter

本秂侑毒 提交于 2021-01-29 14:44:18
问题 When select check box to set enable(false) on second text field and hit enter need to focus at third text field if not select any check box then hit ENTER it can be focus on text field as flow. I should add any code or how can I make it work My GUI: private void chk1ActionPerformed(java.awt.event.ActionEvent evt) { // Set action perform for check box: if(chk1.isSelected()){ p1.setEnabled(false); } else{ p1.setEnabled(true); } } private void chk2ActionPerformed(java.awt.event.ActionEvent evt)

My class inheriting JLabel won't show up but if I change the type to JLabel it does

不想你离开。 提交于 2021-01-29 12:18:38
问题 Ok, so I made a class called Tile. This class extends JLabel. public Tile() { super(); } Should behave the same as JLabel, no? but when I try to use it in my code, it does not show up in the correct position. If I do a call to the bounds of the Tile, it gives what I would expect, yet it is not AT that position. http://puu.sh/58eUg.jpg with the tile used, http://puu.sh/58eVT.png if I used JLabel in the places where Tile was called. Container cPane = getContentPane(); for(int x = 0;x<8;x++) {

Embedding JavaFX in Swing

时间秒杀一切 提交于 2021-01-29 11:09:04
问题 This is my first question here so I'm a bit nervous, but let's get straight to the point. I'm trying to embed a JavaFX scene in a JFrame and I don't seem to quite succeed. The scene sometimes renders properly, but other times it's just grey background. I've been trying to think of a solution for the last couple days, but I just can't seem to find one. Here's the code: public class Popup { public Popup() { SwingUtilities.invokeLater(() -> { JFrame frame = new JFrame("popup"); frame

Images in jar file [duplicate]

一世执手 提交于 2021-01-29 10:50:37
问题 This question already has answers here : Java Path ImageIcon URL .JAR (1 answer) Runnable JARs missing Images/Files (Resources) (5 answers) Closed 7 years ago . I made a java application and bundled all classes in jar file.When I run the project from eclipse my app is running successfully,but it is not fetching the images from the desired directory.Please let me know how can we present these image files to the end user (like we present .jar file) 回答1: Probably you need to implement your own