jpanel

Java Swing mousePressed and getSource() not showing drawed shapes on JPanel

江枫思渺然 提交于 2019-12-25 02:09:07
问题 I am currently trying to develop a puzzle. All I got is my application with my playing-field and gaming-pieces. Next step is to click on one of my gaming-piece to select it and be able to move it with the arrow-keys (furthermore I want to them only to move, if the next step - which will be 100 pixels - does not contain any other gaming-piece). The problem I'm currently running into: Using addMouseListener() on my main JPanel and then using getSource() only returns my playing-field (called

How to get JPanel equal width and height

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 01:58:00
问题 I found the following code from http://www.java-forums.org/new-java/7995-how-plot-graph-java-given-samples.html. I don't understand why w = getWidth() and h = getHeight() are not equal. And how to make them equal to each other? Thanks import java.awt.*; import java.awt.geom.*; import javax.swing.*; public class GraphingData extends JPanel { int[] data = { 21, 14, 18, 03, 86, 88, 74, 87, 54, 77, 61, 55, 48, 60, 49, 36, 38, 27, 20, 18 }; final int PAD = 20; protected void paintComponent

How can I change the JPanel from another Class?

﹥>﹥吖頭↗ 提交于 2019-12-25 01:45:13
问题 Hi, I'm new to Java and I have the following problem: I created a JFrame and I want the JPanel to change when clicking a JButton. That does almost work.The only problem is that the program creates a new window and then there are two windows. One with the first JPanel and one with the second JPanel. Here is my current code: first class: public class Program { public static void main (String [] args) { new window(new panel1()); } } second class: import java.awt.Toolkit; import javax.swing

Switching contentpane in real time

泪湿孤枕 提交于 2019-12-25 01:25:50
问题 I try to make java small project with intro and after full video or keypressed skip to menu. I made enums for state of "game". How i can switch JPanels and stop everything that old one is doing, because intro is also playing music in Thread. contentPane.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { System.out.println("Clicked"); State = GameState.MainMenu; } }); if (State == GameState.Intro) { contentPane.removeAll(); contentPane.add(intro); contentPane

JFrame with tabs is not being displayed

拟墨画扇 提交于 2019-12-25 00:38:13
问题 I have a problem with my login screen. Somehow it is not being correctly... All the objects(JLabel,JButton,JTextfield etc.) is not being displayed correctly. This is how it should look: It only appears once I resize the screen size by pulling at the window border. The JFrame contains 2 JPanels as tabs. This is the code: Login.java package de.immozukunft.windows; import javax.swing.*; import de.immozukunft.tabs.LoginTab; import de.immozukunft.tabs.MySQLConnectionTab; import java.awt

Can we tilt a JPanel at an angle?

江枫思渺然 提交于 2019-12-25 00:37:06
问题 I have image inside the JPanel . I would like to rotate the image. Is it possible to rotate the JPanel using Graphics , Image is rotatable, Just out of curiosity is it possible to rotate JPanel ? 回答1: Yes! This is possible and fairly straightforward too. I haven't done rotations but I have done other affine transformations (scaling the entire GUI up and down) very successfully on a project. I cannot see why rotations should be any different. Instead of trying to scale each component use the

How does one add a JScrollPane to a JPanel

三世轮回 提交于 2019-12-24 23:15:49
问题 I have been searching around for an easy way to implement a JScrollPlane . I am trying to add it to a JPanel , and it will contain a dynamic number of JPanel s (which will be filled with other stuff). Here is my (failing miserably) attempt to make said JScrollPane : final JPanel info = new JPanel(); final JScrollPane infoS = new JScrollPane(info,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); info.setLayout(new GridLayout(0,1)); info

Set size of JPanel, when there are no components in it

陌路散爱 提交于 2019-12-24 21:22:24
问题 I have a custom JPanel. The only thing that is in it, is a drawing of a rectangle, using the drawRect method of the Graphics object. The JPanel is always in a very specific square size, refuses to get any bigger or smaller. Tried overriding the getPreferredSize() method, didn't work. Tried setting different layout managers for this custom JPanel, and also tried every layout manager for the JPanel that hosts this JPanel. Still, the size of the custom JPanel stays the same. As I said, the

Java Swing: Improving cursor response using Threads

不打扰是莪最后的温柔 提交于 2019-12-24 16:35:13
问题 I need to speed up the cursor response which is hovering over a bunch of rectangles. As the rectangles increase in number(or complexity), the straight forward linear algorithm of iterating over the rectangles starts to deteriorate. This hyperlink shows a linear search model(remember to add the break keyword!!!)linear approach To clearly show what I mean,below is code of a JPanel that has two groups of rectangles.The first group is a List of rectangles on the y-axis, the second group is a List

Java swing — Jpanel not rerendering/repainting itself

感情迁移 提交于 2019-12-24 16:04:22
问题 Im using a JPanel with propertyChangeListener and want it to rerender itself based on whenever a particular variable model changes. My code for the same is as follows -- public class LabelMacroEditor extends JPanel implements PropertyChangeListener { private static final long serialVersionUID = 1L; private LabelMacroModel model; public LabelMacroEditor(LabelMacroModel bean) { this.model = bean; model.addPropertyChangeListener(this); setupComponents(); validate(); setVisible(true); } public