awt

Window's content disappears when minimized

末鹿安然 提交于 2019-12-08 19:35:56
问题 I have a simple class that draws a line when mouse dragging or a dot when mouse pressing(releasing). When I minimize the application and then restore it, the content of the window disappears except the last dot (pixel). I understand that the method super.paint(g) repaints the background every time the window changes, but the result seems to be the same whether I use it or not. The difference between the two of them is that when I don't use it there's more than a pixel painted on the window,

Why does java.awt.Point provide methods to set and get doubles but store x and y as int's?

感情迁移 提交于 2019-12-08 19:26:46
问题 As you can see in the Oracle Documentation for java.awt.Point, x and y are stored as int . However, getX and getY return double . While there is a setLocation method that takes 2 double types, there is no constructor that does. Furthermore, the double gets truncated to an int internally anyway. Is there a good reason for this? You might avoid a cast on setLocation by having a method that takes double types, but you have the opposite problem when you call getX and getY . There's also a

Java Swing JList, can't set minimum width

徘徊边缘 提交于 2019-12-08 14:24:11
问题 Trying to simple create a JList with a specified visible row count, but a minimum width. It seems "setMinimumSize()" does nothing though... import java.awt.*; import java.awt.event.*; import javax.swing.*; public class UserInterface { final static private int HEIGHT = 400; final static private int WIDTH = 650; public static void main(String[] args) { JPanel content = new JPanel(); String[] entries = { "Entry 1", "Entry 2", "Entry 3", "Entry 4", "Entry 5", "Entry 6" }; DefaultListModel

Java swing/awt component to draw chessboard [closed]

醉酒当歌 提交于 2019-12-08 14:05:36
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I don't have much experienc with swing/awt. My problem is: I need to draw something like chessboard (NxN). In general I need to get access to every cell to make changes (when program is running e.g. I click button and something is happen

Drawing a selection box using Swing

北城余情 提交于 2019-12-08 13:34:36
I have written an application with a panel and three buttons. I want to add selection this buttons using the mouse. I mean like we have in Windows on the Desktop. I press the left mouse button and with the movement of the mouse the area selection is growing. Is there a specific interface in this or do I have it manually call the appropriate methods for event listeners and there draw transparent rectangle? Here is a picture: So I have a problem when I paint rectangle using event mouse-dragged, button is repainting so user see blinking button. I want to this button don't disapear when I paint

How would I go about creating a custom graphics class for paintComponent to use?

▼魔方 西西 提交于 2019-12-08 11:35:30
问题 I've been searching around to understand better what I am trying to do but with little luck. I'm assuming the answer is much simpler than I realize. I am making a board game for a class project and am using a JPanel to display the graphics (obviously). In the paintComponent, rather than just create everything in one location I'd like to externalize my graphics into a class of there own which I can simply instantiate within paintComponent. Trying to keep everything logically separated and

Java - find a color representing all colors in an image

狂风中的少年 提交于 2019-12-08 09:37:05
问题 I am wanting to sample an image to return a single color that "looks" that a good representation of the colors sampled. I have tried two methods: Taking an average of all the red, greens, and blues and creating an image from that. This rarely produces a color that looks like it came from the image. Finding the "dominant" color from the image. This entails finding the most common color from the image. This is better, but for example, the Mona Lisa produces a dark purple color. This seems to

MouseClicked event to setBackground of a panel

China☆狼群 提交于 2019-12-08 09:10:59
问题 I'm making a GUI pairs guessing game with 9x12 panels to hold a random number in each. I have made it so when you hover over each individual panel, it changes from red to yellow, and back to red once your mouse leaves the panel area. My problem now is changing the color of a clicked panel to green, and any previously clicked panel back to it's original color red. It turns green as intended, but am lost as to how to reset the previously clicked panel back to red after a new panel is clicked. I

Put JLabel on Component in JPanel

元气小坏坏 提交于 2019-12-08 08:12:46
问题 I have JPanel which contain a component imageWindow(object of this) now i want to put a label tag in the center of this imagewindow but i am not able to do so? JPanel imagePanel = new JPanel(); imagePanel.setLayout(new GridBagLayout()); imagePanel.add(ic); //ic is imageWindow obj JLabel l1=new JLabel("First Label."); JPanel example =new JPanel(); example.add(l1); imagePanel.add(example); what i am doing wrong here is screenshow i need to put the label here. i want to put the label at the

Get Click Count Mouse Listener on Touch Screen

ぐ巨炮叔叔 提交于 2019-12-08 08:06:25
问题 Im running a simple JFrame with a JList. I encountered an issue just like this guy> Java getClickCount on touchscreen I know it has been posted already but there were no answers. jList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { System.out.println("MouseClick: "+e.getClickCount()); if (e.getClickCount() == 2) { 回答1: Code below is working.. public class MainTest extends JPanel { public MainTest() { addMouseListener(new MouseAdapter() { public void