swing

Delete row from JTable

北慕城南 提交于 2021-01-28 14:50:44
问题 I need to remove row from JTable. Here is my code : import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import java.awt.GridLayout; import javax.swing.JPanel; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame;

Change the color of one or more nodes in Jtree dynamically

大憨熊 提交于 2021-01-28 14:12:38
问题 I have created Jtree with Root node and 4Subnodes. My problem is like this: I need to change the foreground and background color of a particular node dynamically. How can i do it? Help me with some piece of code. Thank you all in advance... 回答1: How can i do it? I'm sure that JTree tutorial contains valuable info about DefaultTreeCellRenderer, Help me with some piece of code. tons of examples here or here or here 回答2: One easy way I found was to include HTML markup in the node text. The

Java KeyBindings input delay

随声附和 提交于 2021-01-28 13:54:19
问题 I wasn't quite sure how to word the title of this question. Basically I'm making space invaders with JFrames, and using KeyBindings for keyboard input. The keybindings work fine, and I can move the ship around without a problem. However, if I hold down a key, the ship moves 5 pixels and then pauses for about half a second, after which it moves smoothly. When the key is pressed, my code increases the ship's speed (which moves the ship by 5-10 pixels every frame). I'm assuming this is a common

How to display the contents in an array by using mouseListener?

那年仲夏 提交于 2021-01-28 13:31:33
问题 I'm doing a program in which there are 8 shapes contained in an array that will be displayed when you click the mouse. I am new to Java and not that familiar with event handlers and listeners. I am trying to make the shapes appear at the location the mouse is clicked at inside the frame yet I am having trouble since the constructor of each shape use 2 Points as its parameter. Here's an example from the code: import MyLibs.Circle; import MyLibs.Rectangle; import MyLibs.Shape; import java.awt

Do multiple tasks while running code in actionperformed java

让人想犯罪 __ 提交于 2021-01-28 13:19:59
问题 Let's say i have a listener attached to a button. When i press this button, actionPerformed is called and i set a label as visible. Then the calculate() method runs(which has some really long calculations inside it and it takes time). Then i wanna print the results with the show() method. Thing is that i know for a fact that the label will be set as visible after all the code inside actionPerformed will be executed. So my question is : How should i set the calculate method to run on

Do multiple tasks while running code in actionperformed java

自作多情 提交于 2021-01-28 13:19:28
问题 Let's say i have a listener attached to a button. When i press this button, actionPerformed is called and i set a label as visible. Then the calculate() method runs(which has some really long calculations inside it and it takes time). Then i wanna print the results with the show() method. Thing is that i know for a fact that the label will be set as visible after all the code inside actionPerformed will be executed. So my question is : How should i set the calculate method to run on

Do multiple tasks while running code in actionperformed java

假如想象 提交于 2021-01-28 13:18:37
问题 Let's say i have a listener attached to a button. When i press this button, actionPerformed is called and i set a label as visible. Then the calculate() method runs(which has some really long calculations inside it and it takes time). Then i wanna print the results with the show() method. Thing is that i know for a fact that the label will be set as visible after all the code inside actionPerformed will be executed. So my question is : How should i set the calculate method to run on

Do multiple tasks while running code in actionperformed java

时光总嘲笑我的痴心妄想 提交于 2021-01-28 13:18:10
问题 Let's say i have a listener attached to a button. When i press this button, actionPerformed is called and i set a label as visible. Then the calculate() method runs(which has some really long calculations inside it and it takes time). Then i wanna print the results with the show() method. Thing is that i know for a fact that the label will be set as visible after all the code inside actionPerformed will be executed. So my question is : How should i set the calculate method to run on

Custom cursor in java

喜夏-厌秋 提交于 2021-01-28 12:52:40
问题 Recently I'm building a java swing application and want to add a custom cursor. I used the following code, public void customCursor() { Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = toolkit.getImage("pencil.gif"); Point hotspot = new Point(0,0); Cursor cursor = toolkit.createCustomCursor(image, hotspot, "pencil"); setCursor(cursor); } And call the customCursor() method inside constructor. When i run the application my cursor is invisible. I tried giving the absolute path and

Custom cursor in java

情到浓时终转凉″ 提交于 2021-01-28 12:43:31
问题 Recently I'm building a java swing application and want to add a custom cursor. I used the following code, public void customCursor() { Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = toolkit.getImage("pencil.gif"); Point hotspot = new Point(0,0); Cursor cursor = toolkit.createCustomCursor(image, hotspot, "pencil"); setCursor(cursor); } And call the customCursor() method inside constructor. When i run the application my cursor is invisible. I tried giving the absolute path and