jpanel

Problems with detecting mouseClick in a JPanel and preventing circle from painting in JPanel

喜欢而已 提交于 2019-12-11 09:27:25
问题 My current program lets the user move a circle around the JFrame and also change its color by pressing one of the colors presented in the JPanel at the bottom of the JFrame. My code: import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.border.Border; import javax.swing.BorderFactory; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.Color; import java.awt.Graphics;

Paint on a glass pane without repainting other components

给你一囗甜甜゛ 提交于 2019-12-11 09:27:00
问题 Let's say I have a JPanel called content with its paintComponent(g) overridden. This panel usually paints very quickly, but sometimes ( Clarification: the user generates a graphics object that can have thousands of points, which slows down the rendering. It needs to be this way and it's not part of my question) it may take a whole second to repaint due to all of the graphics stuff going on in it. I want to paint a dot near the location of the mouse, but I want this to update quickly and not

JButton orientation within a JPanel

一个人想着一个人 提交于 2019-12-11 08:56:32
问题 I am designing a GUI for an image editor in which I have multiple buttons which apply different effects to the selected image. Currently I have the Display button in the top center of the window, the Load button in the bottom center of the window, and I want the effect buttons stacked on the left side of the window. Here is the image of my GUI, with the ButtonPanel JPanel in red, the FileChooser JPanel in green, and the ImageDisplay JPanel in blue: As you can see, the buttons in the

Java bubble image adapt to text size

。_饼干妹妹 提交于 2019-12-11 08:21:29
问题 I am trying to build some sort of messenger service but I am having issues with the rendering of a text bubble. I started by splitting a bubble into 9 images, The four corner would be static. Where I have an issue is the NORTH, SOUTH, EAST and WEST images. I would like them to repeat themselves similar to the CSS option repeat. Basically, adapting the bubble to the content. I looked around but a lot are Android or IOS solutions. Is there a repeat functionality in Java and can do this without

Override createToolTip() method of JPanel in java swing

拜拜、爱过 提交于 2019-12-11 08:07:07
问题 I have a ListCellRenderer which extends JPanel . Now I try to override its createToolTip() . But it seems like method is not getting overridden. What could be the reason? My Code: public class MyRender extends JPanel implements ListCellRenderer { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value != null) { removeAll(); // -- add data to JPanel. setToolTipText("hi"); return this; } return null; }

Title truncation in JPanel TitledBorder - Java swing

放肆的年华 提交于 2019-12-11 07:51:51
问题 I've got a JPanel with a TitledBorder, but the contents of the panel are narrower than the title in the border and the title gets truncated. I am using BoxLayout for the JPanel which as depicted here pays attention to manual setting of width. I tried to set the minimum, maximum and preferred width of the panel according to the TitledBorder getMinimumSize() function along with the width of its components but all don't work. The only thing that worked was using a box filler but that introduced

GUI Making Arrays of Images that Move Using Mouse Event

不打扰是莪最后的温柔 提交于 2019-12-11 07:47:09
问题 I am pretty overwhelmed at the moment with this assignment. I am only 3 weeks into Java programming and I was given this code and told to modify it in ways I'm not exactly familiar with. So any help would be greatly appreciated. I really want to understand this, so any information would also be helpful. The directions that I'm struggling with at the moment are: "Modify the Model class to store an ArrayList of Turtles. Make Model.update call Turtle.update for each Turtle in the ArrayList. To

Why it shows scrollbar to JScrollPane when we use setPreferredSize for the JPanel which is added to JScrollPane

▼魔方 西西 提交于 2019-12-11 07:46:57
问题 Please see the following block of code import java.awt.Color; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSplitPane; public class test extends JFrame { public test(){ this.setBounds(0,0,300,700); JPanel pnltemp= new JPanel(); //pnltemp.setBounds(0,0,400,1000); pnltemp.setPreferredSize(new Dimension(400,1000)); JScrollPane scrtemp= new JScrollPane(); scrtemp.getViewport().add(pnltemp); this.getContentPane(

Repainting/refreshing JLabels on a JPanel

梦想的初衷 提交于 2019-12-11 07:01:17
问题 I'm having trouble getting my JLabels in a 2D array to update during runtime. The program I'm working on is a variant of Connect Four. I create a 2D array of JLabels, which all default to an ImageIcon containing an image of a blank slot. Players 1 and 2 choose their colors, and on a player's turn, he can click to drop a piece into a column (gravity causes the piece to fall to the bottom or until it lands atop another piece). I'm pretty positive that my addToColumn method is working fine. My

Java JApplet Graphics Double Buffering

爱⌒轻易说出口 提交于 2019-12-11 06:58:11
问题 I'm writing a pretty simple game in Java, and I'm running into the issue of very serious flickering when I play the game as an applet in a browser. That is, all of my sprites, which are being painted on top of a background, are sometimes shown onscreen, but usually not - they repetitively flash onto the screen and then disappear. I've read that double buffering is probably the solution to this, but I'm having trouble implementing it correctly. I'm using a JApplet as the container for a JPanel