swing

Java TextField getText() returns previous string value

那年仲夏 提交于 2021-02-05 05:36:02
问题 I have a problem with Java Textfield that is when I cover all text in the JTextField and input new text immediately(do not pass backspace) into the JTextField, then I use function getText() I get the previous string not current string. Please help for some solutions. Thanks in advance. 回答1: I just tested the problem you described by adding a keyListener to a JTextField and printing the getText() method's return value to the console. What I found out is that it is always one character behind

Java TextField getText() returns previous string value

不羁岁月 提交于 2021-02-05 05:35:23
问题 I have a problem with Java Textfield that is when I cover all text in the JTextField and input new text immediately(do not pass backspace) into the JTextField, then I use function getText() I get the previous string not current string. Please help for some solutions. Thanks in advance. 回答1: I just tested the problem you described by adding a keyListener to a JTextField and printing the getText() method's return value to the console. What I found out is that it is always one character behind

How to display pictures on jpanel with delay?

有些话、适合烂在心里 提交于 2021-02-04 21:50:43
问题 This is the part of the code where i have a problem. I should display each picture every after 5 seconds but it doesn't work. I hope you can help. Thanks EDIT: All pictures are displayed together after 5 seconds JButton btnGenerateNumber = new JButton("Generate Number"); btnGenerateNumber.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent arg0) { ImageIcon apple = new ImageIcon("Resources/apple.png"); try{ for(int i=0; i<labelApp.length; i++){ remove(labelApp[i]); }

Continuously update a JLabel inside a loop from separate thread [closed]

匆匆过客 提交于 2021-02-04 21:37:40
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Improve this question Is there a way to continuously update a JLabel inside a loop from a separate thread. Right now the Jlabel gets only updated once the loop is over. Please do correct me if am wrong, I think this is because the Event Dispatcher Thread is on halt till the other thread finishes

Jlist Custom Renderer

本小妞迷上赌 提交于 2021-02-04 19:49:13
问题 I'm trying to add a i guess you would call it a sub list to each item on a list. I've built a custom renderer that gives the below output. As you can see something isn't right here an i've had no luck tracking down an answer to my problem. I'm guessing i need to change something in the layout of the panel to get the correct result but no idea what. http://i.stack.imgur.com/jCKjJ.jpg import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; import java.awt.GridLayout;

Properly drawing over an image

空扰寡人 提交于 2021-02-04 19:49:08
问题 I'm creating a small image editor and right now i'm trying to give the user the chance of drawing over the image by dragging the mouse (like pencil tool in MS Paint does). I'm having some difficulties since, when i move the cursor too fast, the application can't draw all the pixels which should be colored, just a little number is correctly colored. I tried two solutions to add the colored pixels: at first i created a list where i stored all the points added when mouseDragged was called. After

Cannot add a title page in the GUI based program java [closed]

◇◆丶佛笑我妖孽 提交于 2021-02-04 08:41:07
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 months ago . Improve this question While I was writing this code,I wanted to add the start page where you are able to click the start button to start the actual quiz. I had made the actual quiz structure, but while I was trying to make the start page, it didn't work well. When I combined it the start page did

repaint() method not calling paintComponent

放肆的年华 提交于 2021-02-04 08:40:52
问题 I'm trying to write a program that visualizes simple sorting algorithms using Java Swing. I have a menu with buttons that let the user choose which sorting algorithm they would like to see. My problem is that repaint() is not calling paintComponent after every index swap, so we don't get to see the array being sorted. Instead, the program just displays the array once the panel is made visible, showing the already sorted array. I've tried adding frame.revalidate() but it doesn't do anything

change color JTable cells with getTableCellRendererComponent NOTHING HAPPENDS

拥有回忆 提交于 2021-02-04 08:28:50
问题 I am trying to change the color of some cells in my JTable. I have tried to override getTableCellRendererComponent in a simple example, and it works nice. But when I do the same in my project nothing changes... I have my JPanel with my JTable in a Box like this: boxTable=Box.createHorizontalBox(); box2Table.add(boxTable); //JTable tablaContador = new JTable(datosContador,cabeceraContador); //MODIF COLOR tablaContador.setDefaultRenderer(Object.class, new ColorRenderer()); Doing: System.out

change color JTable cells with getTableCellRendererComponent NOTHING HAPPENDS

岁酱吖の 提交于 2021-02-04 08:28:05
问题 I am trying to change the color of some cells in my JTable. I have tried to override getTableCellRendererComponent in a simple example, and it works nice. But when I do the same in my project nothing changes... I have my JPanel with my JTable in a Box like this: boxTable=Box.createHorizontalBox(); box2Table.add(boxTable); //JTable tablaContador = new JTable(datosContador,cabeceraContador); //MODIF COLOR tablaContador.setDefaultRenderer(Object.class, new ColorRenderer()); Doing: System.out