swing

Java Drawing Multiple Squares in Same JFrame

江枫思渺然 提交于 2021-02-05 11:03:32
问题 I am trying to make an animation with multiple thread. I want to paint n squares where this n comes from commend-line argument. Every square has their x-y coordinates, colors and speed. They are moving to the right of the frame with different speed, color and coordinates. Since I am using multi thread I assume I have to control each squares. So I have to store each square object in the ArrayList. However, I am having trouble with painting those squares. I can paint one square but when I try

Change Images on jframe when a button is clicked in Java

Deadly 提交于 2021-02-05 10:54:16
问题 I have been trying to figure this out why not the next picture showing on the same panel after click the button. I want to separate those classes not into one class and used repaint() to re-invoke paintComponent() with the new pic. Please help me. I am almost dying :( when I run this, the first picture appears well. when the button is clicked to change the first picture to the second one, the Panel just keep on showing the first picture. Thank you. import java.awt.*; import java.awt.event

Change Images on jframe when a button is clicked in Java

我的未来我决定 提交于 2021-02-05 10:54:04
问题 I have been trying to figure this out why not the next picture showing on the same panel after click the button. I want to separate those classes not into one class and used repaint() to re-invoke paintComponent() with the new pic. Please help me. I am almost dying :( when I run this, the first picture appears well. when the button is clicked to change the first picture to the second one, the Panel just keep on showing the first picture. Thank you. import java.awt.*; import java.awt.event

Java custom drawing with paintComponent() and paint()

☆樱花仙子☆ 提交于 2021-02-05 10:39:53
问题 I come from an Objective-C background and I have been developing on the iOS and Mac OS platform for a number of years now. I love the concept of custom drawing and therefore I would like to replicate what had been done by me on the aforementioned platform. In iOS I would call -drawRect() to draw a custom view and then, I could go ahead and add other visual components on top of that drawing. I know that there are equivalents in java swing and awt called paint() and paintComponent() . However,

Java custom drawing with paintComponent() and paint()

非 Y 不嫁゛ 提交于 2021-02-05 10:39:08
问题 I come from an Objective-C background and I have been developing on the iOS and Mac OS platform for a number of years now. I love the concept of custom drawing and therefore I would like to replicate what had been done by me on the aforementioned platform. In iOS I would call -drawRect() to draw a custom view and then, I could go ahead and add other visual components on top of that drawing. I know that there are equivalents in java swing and awt called paint() and paintComponent() . However,

Draw on JPanel from other class

狂风中的少年 提交于 2021-02-05 09:48:53
问题 In my program I try to paint on a JPanel when the mouse is pressed. The mousePressed method is just to test the painting from another class. Later on the spawn method will be called by other class methods. When I press the mouse button spawnPedestrian() is called, but no Pedestrian is painted. Below is a running example with code from my project. If you create a project Roundabout and paste this code in it, you should be able to run it (images are hotlinked). How to fix the spawnPedestrian()

Java GUI Scaling problems

前提是你 提交于 2021-02-05 09:48:29
问题 How i can disable scaling (Windows 10) for java program or process this in code to fix blur on my custom components? I had tried Dsun.java2d.uiScale.enabled=false but it didn’t help. is there any solution to this problem? 回答1: Depending on the Java version you are using, you may want to consider different solutions, especially if you'd like to solve it on your application's side. In any case, and if your concern is just to disable the Windows 10 scaling, you can do so by changing your Java

Draw on JPanel from other class

孤街醉人 提交于 2021-02-05 09:47:25
问题 In my program I try to paint on a JPanel when the mouse is pressed. The mousePressed method is just to test the painting from another class. Later on the spawn method will be called by other class methods. When I press the mouse button spawnPedestrian() is called, but no Pedestrian is painted. Below is a running example with code from my project. If you create a project Roundabout and paste this code in it, you should be able to run it (images are hotlinked). How to fix the spawnPedestrian()

BoxLayout: can't setup child component size

谁说我不能喝 提交于 2021-02-05 09:32:13
问题 I have a JFrame - SuperTest and JPanel - SuperLogin . The login panel has the username and password input fields and a login button. I want it to look like this: but it looks like the pic below, with input fields having too huge height and width. SuperTest.java : import javax.swing.*; public class SuperTest extends JFrame { public SuperTest() { add(new SuperLogin()); setVisible(true); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setSize(600, 400); } public static void main(String[

Java: ImageIcon - image file updating but image icon in Java frame not

十年热恋 提交于 2021-02-05 09:24:12
问题 I have got a ImageIcon in a Jlabel in a JFrame (Java GUI). The ImageIcon should get updated based on pressing a Calculate button (i.e. calcButton.addActionListener(new ActionListener() ) with part of the code in the method: icon2 = new ImageIcon("M:\\Repos\\rtrans\\radTransPlot.png"); Plot1.setIcon(icon2); frame.add(Plot1,gc); frame.setVisible(true); The initial ImageIcon (icon1) is blank: public class RadTransGui { private ImageIcon icon1 = new ImageIcon("M:\\Repos\\rtrans\\radTransPlotEmpty