jpanel

JLabel and JLayeredPane - How to display an image over another image?

拜拜、爱过 提交于 2019-12-21 05:16:10
问题 I try to create a little game in java but I'm in trouble. When I draw a map, I'm not able to display the characters without overwrite the titlesets of the squares. My goal is to be able to display many pictures on the same square (like the titleset of the grass, the character and a tree), so I have to deal with the transparency of my pictures (this is not the problem) and the layer (it is the problem). So how can I display an image on another image? How can I explain to java that I need to

Zoom JPanel in Java Swing

Deadly 提交于 2019-12-20 17:34:22
问题 I have an existing Java Swing application. In the middle of the application is a single JPanel which I want to be able to zoom in and out of. The JPanel has a number of JComponents on it (mostly other JPanels and JLabels ). Also mouse position will need to be adjusted appropriately as well - so mouseevents need to remain same even after the JPanel has been zoomed. As such simply changing the paint methods of each component doesn't seem plausible. EDIT: OK i kind of got it working using the

Panel losing color

孤人 提交于 2019-12-20 07:44:55
问题 When I click on the button that activates the file chooser, and add the resulting file the panel color disappears. Does anyone know why this is happening? import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.JLabel; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing

Adding a MouseListener to a panel

ぐ巨炮叔叔 提交于 2019-12-20 07:41:10
问题 I am trying to add the mouse actions to my panel. This is what the program is supposed to do: Write a program that allows the user to specify a triangle with three mouse presses. After the first mouse press, draw a small dot. After the second mouse press, draw a line joining the first two points. After the third mouse press, draw the entire triangle. The fourth mouse press erases the old triangle and starts a new one. 回答1: I would strongly recommend you start by having a read through How to

Java, putting a JScrollList onto a JPanel

早过忘川 提交于 2019-12-20 07:06:49
问题 I am wondering if there is a way to add a JList on a JFrame with a JPanel. I am making a program and I searched all over the interwebs for an answer but I can't find one. Anyways Preferably the JList with a scrollpane (that works) if it is possible Here is my code: public static void main(String args[]) { JScrollPane scrollpane; JFrame frame = new JFrame(); JList list; String categories[] = { "1", "2", "3","4", "5", "6", "7","8", "9", "10", "11", "12" }; list = new JList(categories);

Java, putting a JScrollList onto a JPanel

余生颓废 提交于 2019-12-20 07:03:50
问题 I am wondering if there is a way to add a JList on a JFrame with a JPanel. I am making a program and I searched all over the interwebs for an answer but I can't find one. Anyways Preferably the JList with a scrollpane (that works) if it is possible Here is my code: public static void main(String args[]) { JScrollPane scrollpane; JFrame frame = new JFrame(); JList list; String categories[] = { "1", "2", "3","4", "5", "6", "7","8", "9", "10", "11", "12" }; list = new JList(categories);

BorderLayout only showing one object

限于喜欢 提交于 2019-12-20 06:47:13
问题 I decided to write a small Java program to experiment around with BorderLayout, because I'm developing a Java game and I need to have 2 objects placed in a single JFrame at the same time, and everyone I asked said I need BorderLayout to do that. So the Java program I wrote is supposed to place a JButton on the JFrame and ALSO place a graphic component (a rectangle in this case). The problem is, only the button shows up, as can be seen in the image link below: http://prntscr.com/3m5ek6 I can't

Using an image for the background of a JPanel and JButton

早过忘川 提交于 2019-12-20 06:39:59
问题 I am trying to use an image I made in photoshop as the background for my GUI. How do I do that? also I made some images I want to display in the button backgrounds after the action is performed... 回答1: For the JButton, use this: JButton button = new JButton("Button Name", new ImageIcon("foo.png"); The Panel is a bit more interesting. This is a good method, though: ImagePanel panel = new ImagePanel(new ImageIcon("foo.png").getImage()); 来源: https://stackoverflow.com/questions/8373006/using-an

JFrame does not add component when JButton is pressed

断了今生、忘了曾经 提交于 2019-12-20 06:39:50
问题 My code is basically about having a frame and it has a button. You press the button you can draw rectangles, getting coordinates from the mouse press and the mouse release. Now, if you remove the button the code works perfectly, here is the code. //testing file package ActionTest; import java.awt.*; import javax.swing.*; public class MouseTest { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { JFrame frame = new MouseFrame(); frame.setTitle(

BorderLayout only showing one object

≡放荡痞女 提交于 2019-12-20 06:28:03
问题 I decided to write a small Java program to experiment around with BorderLayout, because I'm developing a Java game and I need to have 2 objects placed in a single JFrame at the same time, and everyone I asked said I need BorderLayout to do that. So the Java program I wrote is supposed to place a JButton on the JFrame and ALSO place a graphic component (a rectangle in this case). The problem is, only the button shows up, as can be seen in the image link below: http://prntscr.com/3m5ek6 I can't