FAQ Database Discussion Community


Disable close button in Processing

java,awt,processing
Is there a way to disable the window's close button in Processing, during a certain event? Here is a snippet of the code: frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { if (youWin == 0) // condition that is supposed to keep the application opened { JOptionPane.showMessageDialog(frame,"You can't exit until...

Get the colour of a pixel that has specific coordinates within a JLabel

java,swing,colors,awt
I am writing a program in which I need to find the colours of clicked pixels within an image (the image being stored as a JLabel), and plan to use an AWT Robot to do the job. However, as far as I know, I can't associate an AWT Robot with...

What is the difference between JRE options java.awt.headless and java.awt.headlesslib?

java,awt
I have used the former many times (-Djava.awt.headless=true) in order to prevent the infamous "no DISPLAY found" error for some applications which used some graphics methods in the JRE. But since then I have also learned of the existence of the second one. In spite of hours of searching around,...

How can I map an action for option (Mac keyboard) up for a JTextField?

java,osx,swing,awt,jtextfield
Looks like option up can be caught only with AWT (i.e., adding key listener). Is there a way to do it without having to mess around with AWT?

Proper method for creating splashscreen with drawImage(g)

java,awt,lifecycle,japplet
I'm learning to construct a JApplet, though as of yet haven't traveled far beneath the surface. I have an image(.png) which would ideally be painted by paintComponent(s) before the interface is "painted" or rather added from within the paint() method. Interestingly, the JApplet only loads as intended after it is...

java awt or Swing component missing or not shown

java,eclipse,swing,awt
i've been charged with a new software tool, and i m trying to test it. PROBLEM: I noticed a difference between mine GUI and the GUI of the tool run on the server: a component is missing! It is like if it's not shown, because i went in debug mode,...

Java AWT - Add a popupMenu to a Panel / Frame without Layout

java,user-interface,awt,popupmenu
I need to create a GUI which has to provide a PopupMenu. I managed to do this but it only appears if I set the Layout null - In this case there is the problem, that none of my features appears only the popupmenu. I am not allowed to use...

How to intercept paintComponent from Custom JButton

java,swing,awt,jbutton,paintcomponent
I created a Custom JButton with transparent background and a drawn line from graphics.drawRoundRect() but when I start my program for testing, my JCheckbox keeps appearing on top of the button. It looks like this at the beginning And this is after I hover over the Button with the mousecursor...

System tray text instead of icon

java,swing,awt
How can I display text in the system tray instead of an icon? I want to display a percentage for example. final TrayIcon trayIcon = new TrayIcon(createImage("image.png", "tray icon")); The code above is to set an icon, but how can I set text such as 100% to display in the...

JTextField Everything looks ok in Eclipse but won't compile

java,swing,awt,jtextfield
Can someone please tell me what's wrong with this code? I need it to pop up a frame and fill the frame with certain field a namer field and an intake field and also display a button at the bottom of the grid. Any help would be welcomed, Thanks!! import...

Issue at sorting and showing array in AWT (Java)

java,arrays,swing,user-interface,awt
I recently sign up in this helpful webpage. So, I need your help Please. I've working with GUI, using AWT (with non Swing Components). So. I must fill a 1D Array, using POO (not structured) with Random integers, from that array I have to calculate the average; having the average,...

NullPointerException error while using Graphics class in java

java,swing,nullpointerexception,awt
I'm completely new to java. I'm trying to write a simple java program that takes the input for coordinates and height,width for a rectangle and draws it. But i'm getting NullPointerException error. Here is my code: import javax.swing.JFrame; import java.util.Scanner; import java.awt.*; public class shape extends JFrame{ public int x,y,width,...

Java alternatives to AWT to capture mouse events?

java,awt
Are there alternatives to AWT for getting mouse press events in Java?

In Java, what is the default JPanel height and width?

java,swing,awt
I have created class as below. When I create an object called drawpanel of this class and add to the frame using frame.getContentPane().add(BorderLayout.CENTER, drawpanel), I get a rectangle with black background as expected. Does it mean that the Panel's this.getWidth and this.getHeight by default has the same the height and...

Java AWT: Setting background of Canvas changes the background for the whole frame

java,canvas,awt,layout-manager
Why is it that changing the background color for the java.awt.Canvas, changes the background for the whole frame? I set up a Frame object as follows: public class Gui extends Frame { public Gui() { setSize(800, 600); setLocation(0, 0); Canvas cd=new Canvas(); cd.setSize(500, 300); cd.setBackground(Color.BLUE); add(cd); addWindowListener(new WindowAdapter() { @Override...

draw darkened bufferedimage without touching it

java,image,awt
I'm currently making a tile-based strategy game, with its map made of a bunch of sprites (BufferedImages), drawn by java.awt.Graphics.drawimage(..) What i want is to be able to draw those sprites a tone darker if the player is too far away from them. I've seen a lot of similar questions...

Cannot load font in JRE 8

java,fonts,awt,java-8
I cannot load a font from an S3 Inputstream in JRE 8. I do not have issue if a system is installed with JRE 7, JDK 7, or even JDK 8. val fontInputStream = s3Client.getObject(bucketName, objectKey).getObjectContent val customFont = Font.createFont(Font.TRUETYPE_FONT, fontInputStream).deriveFont(Font.TRUETYPE_FONT, 20F) The error that I got is Exception in...

Swing 2D game low performance

java,performance,swing,awt,repaint
I am making a clone of Flappy Bird. I was doing just fine performance-wise: 60 fps. This was when it had 1 pillar/obstacle only. As soon as I added 3 of them my fps dropped to 30 and below. Then game is unplayable now. I get that this has something...

Reverting color change in Jbutton when another Jbutton selected

java,swing,user-interface,awt
My GUI has a list of filtered entries from a db file. For each entry, I have a select Jbutton which shows more details for each entry. What I am trying to achieve is to have the select JButton change color when pressed, and revert to original color when another...

Unwanted JPanel border in JFrame

java,swing,awt
I am trying to fill JFrame with a JPanel and colour that JPanel, but for some reason I get a border on the bottom right edges. My code: public class Main extends JFrame { public MyPanel myPanel = new MyPanel(); public static void main(String args[]) { Main main = new...

addActionLister parameter

java,swing,event-handling,awt
I am getting expected output when i am using "this" reference in addActionListener() call, how can I achieve it using the object call directly ? When i am using jb.addActionListener(new EventHandling1()); I am getting error -"Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException". Also which object needs to be passed to this method...

Unable to draw over a JPanel

java,swing,awt,graphics2d
I am trying to draw on a JPanel. When the function drawField is called, it draws nothing. What could be the reason for it? private void drawField() { try { Graphics2D field = (Graphics2D) jPanel2.getGraphics(); field.drawLine(0, 0, 100 , 100); }catch(Exception exc) { exc.printStackTrace();} } It is called from the...

Creating a Frame with MenuBar - Size not recognized by pack(), menubar is being cutoff

java,awt,menubar
for an exercise I need to have a frame consisting of 2 buttons, and, if you click one, some text displaying. I need to also add a menubar. This works fine, it shows in the frame, but only the first menu. As I already found out, the problem is that...

Is calling repaint from paintComponent a good practice

java,performance,swing,awt
For some UI components in our application, we override paintComponent, which under some conditions "recursively" calls itself by invoking repaint. We use this approach to achieve high refresh rate of animations in the component. For instance, a progress bar we use looks something like: public class SimpleProgressBar extends JPanel {...

How to extract text by a selected area from a PDF file using iText?

java,swing,pdf,awt,itext
I am working on a program that extract texts from a PDF file in a specific area, I am using java and iText library. Right now, i can extract data by taping the area coordinations using this code: import java.io.IOException; import com.itextpdf.text.Rectangle; import com.itextpdf.text.pdf.PdfReader; import com.itextpdf.text.pdf.parser.FilteredTextRenderListener; import com.itextpdf.text.pdf.parser.LocationTextExtractionStrategy; import com.itextpdf.text.pdf.parser.PdfTextExtractor;...

How do i add a mouseListener to a anonymous JLabel object?

java,swing,awt,jlabel,mouselistener
Currently I'm using a for-loop to populate the JPanel with numbers from 1-31 So basically, What I want to do is if let say i click on number 1, it will do show System.out.println(1); Here's the code: public class MonthPanel extends JPanel implements MouseListener { public MonthPanel() { setLayout(new GridLayout(6,7));...

How to create a circle using GeneralPath and apache POI

java,awt,apache-poi,powerpoint
How to create a circle using GeneralPath and apache POI. I want create any circle in a MS PowerPoint Slide. I user appache POI in Java program. String exportFile = "pptx/export.pptx"; XSLFSlide[] slides = ppt.getSlides(); XSLFSlide slide = slides[0]; int x=300; int y=400; int R=50; java.awt.geom.GeneralPath circle = new java.awt.geom.GeneralPath();...

Java displaying images on one another and move it

java,swing,awt
I am a beginner in Java, and i have to build a program to move a boat on a sea. My idea is to insert an image as a background screen and then put over another image that would represent the boat. I don't know how to make this. How...

CardLayout syntax // .add()

java,awt,cardlayout
From following code snippet which I taken from CardLayoutDemo. final static String BUTTONPANEL = "Card with JButtons"; final static String TEXTPANEL = "Card with JTextField"; - //Create the panel that contains the "cards". cards = new JPanel(new CardLayout()); cards.add(card1, BUTTONPANEL); cards.add(card2, TEXTPANEL); I don't understand the usage of 2 strings...

Why cant i paint on the panel

java,swing,jpanel,awt,drawing
I have made three panels south, east and north, i am trying to draw a circle on the north panel but i just cant figure out why it is not drawing.Here is my code: What i want is a small application that draws circles of different sizes and colours chosen...

Starting java desktop app from headless mode

java,process,awt,headless
I have created a java process that runs headless in the background that monitors mac machines. Part of the monitoring includes taking screenshots of the user's action and occasionally bringing up a chat window. I am under the assumption that none of these actions can be performed from headless mode,...

Open AutoCompleteField on click

java,eclipse,autocomplete,awt
I'm using the Eclipse AWT framework, and I've got a combobox. I've set the visible amount of items in the combobox to 0, so that clicking the dropdown doesn't show anything (even though the box is populated). I have an AutoCompleteField on the box, so that anyone typing into the...

Why the getFont() method can't be called and give out NullPointerException.

java,swing,user-interface,fonts,awt
/My objective is to make listener objects to this GUI so that whenever there is a change in the font style or font family selected, or the "OK" button is pressed, then the full name of the font is displayed in the text field. Thank you in advance./ import java.awt.*;...

Is java.awt.GraphicsConfiguration thread-safe? What are the alternatives

java,thread-safety,awt,bufferedimage,swingworker
I'm extending javax.swing.JComponent to display a variable number of tiles, which all have the same size. If a tile needs a new appearance, a SwingWorker's doInBackground() renders a new BufferedImage for it. In done(), the image is stored and JComponent.repaint() is called, indicating the updated area and an intended delay....

How to implement .png pics in a JFrame?

java,graphics,jframe,awt
What I want to do is making a window, a GUI, and putting an image in it. I watched a YT tutorial (https://www.youtube.com/watch?v=Ap20Qw77TzY) and copied everything similar but the Window I make has no image at all. I tried different file types like .jpg and different window sizes, matching he...

java.awt.Point class in Android

java,android,awt
I would like to change java.awt.Point to some similar classes that can replace this. This is a really hard problem for me, because Dalvik VM can't resolve AWT classes, but the given java algorithm uses it. Exact error message: Point cannot be resolved to a type I have also tried...

Java Graphics drawImage method very slow on OS X

java,awt
The drawImage(image, x, y, null); method used on a Graphics object in a JPanel class is taking a long time to complete and making a game run at low FPS, particularly on MacBook Pros it's been tested on - Linux machines appear to run it very well. The time it...

How to bring the Image in Java GUI To a new line?

java,swing,layout,awt,layout-manager
I am trying to make a simple gui window with images. Here's my code: import java.awt.*; import javax.swing.*; public class Image extends JFrame { private ImageIcon [] image = new ImageIcon[10]; private JLabel [] label = new JLabel[10]; Image() { setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); for(int i=0; i<10;...

Pass values to class

java,awt
I am trying to pass x and y coordinates to a constructor in a class using java.awt.Point. My main class is throwing an error saying "The constructor Quadrilateral(int, int, int, int, int, int, int, int) is undefined. I thought when passing to my constructor 'public Quadrilateral(Point... points)' i could pass...

Java mouseReleased() method query

java,awt,mouse
I have taken the following code from a learning resource. When I run the applet, I notice that 'Up' is only displayed after having dragged the mouse. 'Up' is not displayed if a mouse button is pressed then released in the same location. Why is 'Up' not displayed in the...

Can't render unicode characters with Graphics2D even though they are supported by the font

java,unicode,fonts,awt,graphics2d
I try to render text to a BufferedImage and that works quite great but I can't render any characters that are not ASCII (at least as far as I can see). All I could find was that it's because of the font so I downloaded Google's "Noto" fonts that seem...

Two labels in the middle of center

java,swing,user-interface,awt
I want to place two labels in the middle of the center of a window. I get it working with 1 label and the following code: Screenshot: http://abload.de/img/scr1g6u0f.png public static void main(String[] args) { JFrame contentPane = new JFrame(); contentPane.setBounds(100, 100, 450, 300); JPanel centerPanel = new JPanel(new BorderLayout()); JLabel...

Drawing a dynamic graph that changes in real time [closed]

java,swing,twitter,awt
I have this code ..it prints real time tweets based on a filter applied by me and searches for the following sub strings in the tweet, if there then that particular counter specific to that sub string gets incremented. Now , I want to draw a graph taking these 2...

Java - Calling a variable from a different class which's value is taken from a JTextField when a JButton has been pressed

java,swing,variables,awt,eventlistener
Im trying to create a choose your own destiny adventure game. I have created the gui which looks like this: The JTextField shown is going to be the input box which is entered when the button is pressed. Im trying to write the code so that when the button is...

Java: Displaying Positions correctly in Tortoise vs. Hare Applet

java,image,applet,awt
I'm currently working on a Project that shows a tortoise vs. hare race in real-time as an Applet. A random number is chosen, and the animals either move forward, backward, or not at all based on that number. My problem is getting the animals to be seen in real-time. It...

How can my MVC listener distiguish between different buttons

java,model-view-controller,awt
This is my first time trying the MVC design pattern, and I'm trying to figure out how my controller class can tell, when a different button is pressed, and how it can then pass it on to model public void addController(ActionListener controller){ System.out.println("View : adding controller"); btnGo.addActionListener(controller); btnBack.addActionListener(controller); } That...

Drawing point matrix too slow in Java AWT Canvas

java,canvas,awt
I am trying to implement Conway's Game of Life to teach myself Java. Coming from C/C++ it is quite understandable as well. So far I've been rather successful and (I think) I'm almost done. The code seems to work but there's two things that are still bugging me quite a...

How to move JFrame shape

java,swing,animation,awt,java-2d
I'm trying to develop a simple game. The games is about the shapes. Shapes will move and we'll catch by mouse. I have already created a oval and given size of oval graphic. But I cannot move this shape repeatedly. I think I need to use timer class. I have...

Why is getHeight() not equal to the frame height?

java,swing,graphics,awt,jcomponent
I am making a bounc*ing cube that moves around a frame. To detect the boundary of the frame, I used getHeight() and getWidth() from the JComponent in the JFrame and calculate the possible boundary so that the cube can rebound. It works totally fine for getWidth(). However, I cannot make...

Drawing with timer is not working

java,swing,timer,awt,draw
I have problem with drawing in Java. I think my code is right, but when i place it to loop with timer, it will not print anything. I want to do every second repeat the doDrawing(g) method. Now it will only prints the text prom system.out but no drawing. package...

How do I successfully use the Thread.sleep() method in Graphics?

java,exception-handling,applet,awt,thread-sleep
This is my code so far: // Imported Classes public class Timer extends Applet { public void paint (Graphics page) throws InterruptedException { Thread.sleep(1000); } } I just want to know how I can get this to work. I've used the Thread.sleep() method in other code before, but never with...

Change Color of MenuBar, Menu, and MenuItem in Java using the AWT Components

java,awt
I've been searching around for a bit, but I haven't found an answer as to whether or not it's possible to and how to change the background, text, foreground, selection, and text selection colors of the MenuBar, Menu, and MenuItem AWT components. So-far I've tried the following solutions, but neither...

Adding 2 Integers using AWT

java,swing,awt
I'm trying to create a Java AWT program with these codes: import javax.swing.*; import java.awt.*; public class Exer1 extends JFrame { public Exer1(){ super ("Addition"); JLabel add1 = new JLabel("Enter 1st Integer: "); JTextField jtf1 = new JTextField(10); JLabel add2 = new JLabel("Enter 2nd Integer: "); JTextField jtf2 = new...

How to add a button without creating a new window from another class

java,awt
Maybe I am understanding this concept totally wrong but I am trying to create classes for buttons and have them called in a main GUI class so they appear on that window but I don't exactly know how to call these button classes to the main GUI class. I'm currently...

Java custom control rendered differently than in gui designer

java,swing,awt
I have a custom control that I've created. It functions properly but is rendered incorrectly. As can be seen the designer (netbeans) keeps everything neatly packed. However in the running program there are spaces and the text on the buttons does not show. Here is the code. public class AllocateSpinner...

pass a value obtained from a JButton to a variable

java,swing,awt
so my problem is that i'm making a really simple number guessing game in java swing, i added a JButton and a JTextField, i want to click the button to get the value written in my text field and then pass it to a do while loop that's gonna make...

My code about polygon is not working

java,applet,awt
i had a problem about polygons , i wrote my code but it is not working.Possibly i missed something because i don't have any error message . import java.applet.Applet; import java.awt.Color; import java.awt.Graphics; public class drawPloygon extends Applet { int [] x ={20,20,30,40,40}; int y []={40,20,30,20,40}; public void paintPolygon (Graphics...

JButton variable not found

java,swing,radio-button,awt,background-color
I am trying to change the background color on click of a radio button, but the second radio button, "bt2" variable is not found by the compiler. I keep getting this error message: "cannot find symbol bt1" in the e.getSource()==bt1 Here is my code: public class ColorChooser extends JFrame implements...

AWT Frame does not handle events

java,awt,mouselistener
The frame opens and close normally but mouse click doesn't work. import java.awt.Frame; import java.awt.Graphics; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; //Create a frame window that responds to mouse click public class AWT3 extends Frame { String Mmsg=""; int mouseX=0, mouseY=0; public AWT3() { addWindowListener(new MyWindowwAdapter(this)); addMouseListener(new MyMouseeAdapter(this));...

Add a different ActionListener to anonymously referenced JButtons in a JToolBar

java,swing,awt,jbutton,jtoolbar
I'm trying to add four JButtons to a JToolBar, each with a different ActionListener. I'm wondering if there is a way to add an ActionListener to an anonymously referenced JButton, or if I have to specifically define each button and add each listener. Currently, this is what the code looks...

Java- Toolkit.getLockingState not updating

java,awt
I am trying to make a simple Robot program that needs to know if scroll lock is on. I read a different question and was pointed to Toolkit.getLockingKeyState(). However, this method correctly tells whether scoll lock was on when I started the program, it refuses to update when scroll lock...

How to select all files in a FileDialog?

java,linux,awt,filedialog
I want to select all files to exclude them from being displayed in my FileDialog. FileDialog fileDialog = new FileDialog(this, "Some Title", FileDialog.LOAD); fileDialog.setFilenameFilter(new FilenameFilter() { @Override public boolean accept(File dir, String name) { if(name.endsWith(".*")) { return false; }else { return true; } } }); fileDialog.setVisible(true); In my code you...

Issues with apache poi and swing in Java

java,swing,awt
I am using apache POI library in order to change automatically a word file using java code. I have create an JtextField in which I import values to program and I tried to change the bookmarks of the word file with those given values. When I run my program I...

JFrame setVisible not working

java,swing,user-interface,jframe,awt
I am building a log in form once the login button is pressed, it closes login frame and should show main menu. the problem is no matter what I do, it gives me an error cannot find symbol setVisible Please help me out import java.awt.*; import java.awt.event.*; import javax.swing.*; import...

How to get JTabbedPane in JSplitPane to fill the whole window?

java,swing,awt,layout-manager
My JTabbedPane is in a JSplitPane in a JPanel, like this, but I don't want it to be small like that: I want it to look like this: How do I do that? Here is my code: Tabbed_Tables.java public void setupWidow(){ JPanel left = new JPanel(); JPanel right = new...

How to use panels in applets?

java,applet,awt
I need to write a strategic game which contains awt panel. Scenario:- Firstly, I need to read from a txt file(my map) and draw my images based on the txt file. (i did it in the code below). public class temp extends JApplet implements Runnable,MouseListener { public void init() {...

How can I make this paddle move in my Pong Game?

java,swing,awt,pong
In java I am trying to create a pong game and so far I have a moving ball that bounces off the walls and a paddle that stays in the same place. What code can I add to make the mouse move the paddle. I want the mouse to click...

How to rotate a line based on a given number of degrees

java,user-interface,graphics,awt,computational-geometry
I have a line drawn with a Graphics object. I want to rotate this line a certain amount of degrees based on how much the mouse is dragged. I can get the number of degrees i need to rotate it but how do i then rotate the line based on...

Need help getting this simple ferenheit to celcius application working in java

java,swing,event-handling,awt
I need this application to convert the number entered by the user in the JTextField into celsius and display it in a JLabel. It seems to be having problems parsing the the data entered into a double? This is one error among many. Can anyone help me figure out whats...

Java: convert java.awt.Color to javafx.scene.paint.Color

java,javafx,awt
How can I conver one to another? I thought a way via rgb string, but this case alpha layer is ignored. So the question - how to convert one to another with alpha?

Integer won't appear in a TextField

java,awt
I have a problem with my program. I'm trying to put an integer in a textfield. This is my code: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.event.MouseEvent.*; public class GradingSystem extends JFrame{ public GradingSystem(){ super("Grading System"); JLabel pre = new JLabel ("PRELIM GRADE: "); final JTextField pre1 = new...

Create icon for java application as in skype

java,swing,awt
Skype icon is little and hides on the bottom left corner of my desktop near the clock. Can I create something like this of my own application on java with Swing or Abstract Window Toolkit?

Group JMenuItems in Java

java,swing,awt
I am creating an application in Java in which I would like the Menu Items to be grouped like we see in many applications. Here is an example: Notice how a gray bar is visually separating the options. How is this done in Java (Swing) — can it be done?...

Thread errors when running Java game

java,multithreading,swing,awt,event-dispatch-thread
I am getting some strange errors when running my Java game. I've been working on this game for weeks as a project for my computer science class and it is due on 6/4/2015, so I appreciate any help. Initially I wrote the game in a class called Game and ran...

How to keep java.awt.List from covering javax.swing.JMenu

java,netbeans,drop-down-menu,awt,jmenu
To put this simply, I have some Menus in my Menu Bar that, when at start of the application, goes over a List when you expand it. However, if the List is ever updated, the Menus will go behind the List, covering Menu Items. I have theorized that I need...

How to draw bricks in Java Breakout game?

java,awt
There's a breakout game that's been partially created for me; currently it only has a bouncing ball and a bat; there are no bricks which the ball can hit. I need to add code to generate bricks but I'm struggling; I have no idea how to approach this as I'm...

How do you make text in a frame change dependent on cursor position?

java,swing,awt,frame
I have a program that is basically just supposed to change the text of a label when your cursor enters a polygon that is shown on the JPanel. I have tried a few different things with nothing working. Currently I am trying an if statement to make it choose which...

GridBagLayout don't take all the window place

java,swing,awt,layout-manager,gridbaglayout
Hi have a very simple question, why my gridBagLayout don't take all the disponible place on my window ? here the code : public class FenConnection extends JFrame { private static final long serialVersionUID = 4799549157439445680L; private String adresse; private int port; private JLabel infoLabel; private JTextField tf_adresse; private JButton...

Display tables of a database in java

java,mysql,swing,awt,resultset
I'm working on a java application, and I want to display the list of the tables in a Mysql database, I searched on the net and I found that "SHOW TABLES FROM [DB]" is the appropriate request, but how can I dispaly the result of this last on a java...

Refresh custom container through a button inside it in Java

java,awt,refresh,components,containers
Good morning, I have a class that inherit from java.awt.Container. His scope is to wrap a list of Files showing them vertically as a "file name Labels + delete Buttons" list. files are shown properly and every time a new one is added, it refresh correctly. The component class's code:...

Weird output for Graphics code

java,swing,graphics,awt
I am attempting to make a Connect Four game to improve my ability with Java Graphics and as a school project. The background for the game will be a blue JPanel and the game board will be a separate JPanel that will be placed on top of the background. See...

Java - How can I put canvases on top of each other using the OverlayLayout LayoutManager?

java,swing,awt,overlay
I want to put 2 Canvas objects on top op each other. Their backgrounds should be transparent (I did not address this yet). I want a simple way to work with Photoshop-like layers. I want to use as less Swing objects as possible. I have a Container object that contains...

Java import wildcard not importing everything inside package

java,import,awt,actionlistener,wildcard
I'm writing a Java program that has a button with an action listener: JButton button = new JButton("Change"); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { label.setText(textField.getText()); } }); At the top of the file, I have these two import statements: import java.awt.*; import javax.swing.*; I know this is...

Find inside coordinates of polygon in tile based map

java,awt,coordinates,polygon,java-2d
If I have all of the outer edges of polygons in a list how would I go about finding the inside coordinates?? To make matters simple I drew the following image to represent the problem: I need to find the inside of 'buildings' in a tilebased game. outside walls -...

GridBagLayout button.setVisible (true/false)

java,awt,layout-manager,gridbaglayout
Trying to build a really simple UI with GridBagLayout, but when using setVisible(false/true) on Easy/Medium/Hard buttons, as expected the whole thing explodes. How do I set the textfield to be on top of the Check button? I did read the doc but having hard time grasping the logic behind all...

I can't modify my boolean fields?

java,swing,boolean,awt
Well the question explains it, no matter what I do I can't modify my Boolean fields. The following code is a class from an assignment I'm doing but I need to be able to modify Boolean values in order to do it which I can't for some reason so I'm...

How do I delete objects in a Java game

java,awt,java-2d
I have a object in my java game which is going to be a coin, currently its just a rect made with g.setColor(Color.yellow); g.fillRect(x, y, 16, 16); I have collisions set up to give the player points when they touch it, and that works fine, but how do I make...

Continous double buffering solution not working

java,awt,java-8,doublebuffered
I'm attempting to double buffer an image containing a polygon in the method paint() using AWT. Using an Image object for the buffering process, I set the image background to black, draw the polygon to the image and then draw the buffered image to the screen. I then call repaint()...

Cannot instantiate the type ColorModel

java,awt,bufferedimage
Please don't dislike this "generic question", since it really is a problem. I also searched other questions and the problem there was always that the people wanted to instantiate interfaces. That's not my case. The class ColorModel is not an interface and has a constructor that takes an int. Why...

Java Inconsistent Stack Overflow

java,image,exception,awt,stack-overflow
I've been working on my final project for my AP Computer Science class and am modifying the AP Picture Lab to do it (all of the source code is available at https://github.com/jvperrin/ap-picture-lab). For one portion of my project, I implement a depth first search to get adjacent pixels to the...