Swing/AWT/SWT :: Redrawing Images Causes Flickering On Screen
Mar 12, 2014
i'm currently doing my system now and my problem is about inserting an image to my jframe form with thread because if i insert image and when i run it it blinks too slow comparing if i use simple oval it doesnt blink.
why is it that if i wrote the code like this.
public void DrawSnake(Graphics g) throws IOException {
Image image = ImageIO.read(this.getClass().getResource("body1.jpg"));
Image image1 = ImageIO.read(this.getClass().getResource("body.jpg"));
Image headr = ImageIO.read(this.getClass().getResource("headr.jpg"));
Image headl = ImageIO.read(this.getClass().getResource("headl.jpg"));
[Code] .....
View Replies
ADVERTISEMENT
Jan 12, 2011
I need to create a program that draws a graph, but for now, all I have done is two lines: the X and Y axis. The program is designed in a way as to automatically resize the graph when the window is resized.
Is this code in some way extremely inefficient? I get TERRIBLE flickering when I resize the window. Is there something that will at least reduce the flickering?
mainApp.java:
import java.awt.*;
import javax.swing.*;
public class mainApp {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(300,300);
frame.setVisible(true);
[Code] ....
I have added a screenshot that shows the window flickering.
View Replies
View Related
Jul 28, 2014
I am trying to call another swing frame from my current frame. And after calling second frame i dispose the current frame.
But while second frame coming on the screen, current frame gets dispose and second frame takes some seconds to appear on screen.
So its creating a bad flickering effect on screen and its not suitable for my application.
I want that first frame will call sencond frame and it will not look like second frame is called. I just want to cancel flickering effect.
Here is my source code.
1st Frame:
public class Welcome extends JFrame {
JFrame f;
JTextArea nameField,nameField1;
JLabel lable;
[Code] .....
View Replies
View Related
Feb 25, 2015
I want to create off-screen images by Canvases in multi-thread environment.
I know that I use methods of GraphicsContext2D to draw on Canvas. Can I do this on Canvas which is not added to Scene ?
How can I get an image from a canvas after I invoke GraphicsContext2D methods? Can I get images in multi-thread environment ?
View Replies
View Related
Aug 14, 2014
I have moved this to its own thread because I was concerned that I might have hijacked the other OPs thread. As I stated earlier, I decided to try changing the arrowHead on a JComboBox since it should be easy. I created a polygon so I could fill in the shape. However, I believe that the graphics context passed to the paint method has been rotated counter clockwise by 90 degrees. I had assumed that (0,0) would be upper left corner. But (0,0) is lower left corner and (0,height) is lower right corner. Rotate those 90 degrees clockwise and you get them in the (my) expected positions. I also grabbed the AffineTransform from both the paint method and a JPanel paintComponent method. If you examine the trig values for each transformation you will see they are different.
It is not documented in the paint interface. It could just be related to the Nimbus look and feel. I have not checked out others. I did a web search and did not see any info regarding this.
Attached is my modified version of KevinWorkman's code posted in Changing the Foreground Color of ArrowButton of JComboBox in nimbus LaF. I commented out the part that draws the Triangle (It points right instead of down). The key are the circles which should locate the top left and bottom left points.
Java Code:
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.geom.AffineTransform;
import java.lang.reflect.InvocationTargetException;
[Code] ....
View Replies
View Related
Sep 29, 2014
I have created a java gui on Windows 7 with Eclipse EE, using a screen resolution of 1366 x 768. I used groups with specified boundaries. For example:
final Group g5_script_data = new Group(shell, SWT.BORDER_SOLID);
g5_script_data.setText("Current DB");
g5_script_data.setBounds(0, 0, 680, 380);
g5_script_data.setBackground(green);
The groups cover the whole screen.
However my colleague with a smaller resolution looses the far right of the screen.
As this is a proto-type and I'm new to Java I don't want to rework everything or convert it to say a grid layout until the proto-type is accepted and I can start from scratch with a real detailed design. It already has 6500 lines of source.
Just wondered what is my quickest/easiest way to get my app to display on a slightly smaller resolution. For sure it will not be anything silly. Something like 1280 x 768 to 1366 x 768 would do.
View Replies
View Related
Feb 11, 2015
I had developed small GUI using swing group layout, which is nice to see on windows, but when I tried it on Linux the GUI look is varied. Then I set the GUI height and width by taking screen resolution, still it is varies the screen look. How I can make the GUI such that it looks the same on all screen resolutions.
View Replies
View Related
Mar 11, 2014
I'm writing my first bigger program (mysql connection and the first thing bigger than 300 lines ). What I'd like to do is to render data from MySQL using JTable - I managed to handle all the queries but I don't know how to update the table on screen. I've tried to use repaint() but nothing happened. I'm not posting whole code because you'll probably not interested, below are the most important things. I thought about using TableModel but how.
public class Main implements ActionListener{
JTable table;
public Main() {
JFrame frame = new JFrame("Frame");
frame.setLayout(new FlowLayout());
frame.add(table);
[code]...
View Replies
View Related
Nov 6, 2014
how to develop carousel for images using java swing
View Replies
View Related
Jun 17, 2014
I have a question about the execution of code to draw images relative to code that comes after that. I don't normally do this sort of thinghere's the problematic code:
int stn = 0;
while (stn < 10)
{
glb1.xOfText += 20;
glb1.yOfText += 20;
gc1.drawImage(glb1.img1 , glb1.xOfText , glb1.yOfText);
TimeKeeper.pause(500);
stn++;
}
Where glb1 is a final reference to an object that holds common data for the game.while its x and y values say they are for text, they are also used for image placement (at least during this testing phase.)
gc1 is the "graphics context" of the canvas that the images are being drawn on.
The person who wrote this said, "When the attached code is run, the calls to TimeKeeper.pause(500), which in turn call Thread.sleep(500), are all executed in row, and then the results of drawing the image 10 times is displayed. (I know because some of the previous image pastes left some visual data behind.)"
I recall from reading about drawing graphics (a long time ago) that drawImage() could take time, but I don't know why the thread does not indeed sleep between calls to drawImage().
View Replies
View Related
Apr 14, 2015
I am currently creating a Twitter Application within Java Swing using JSON. I have the JList populating with Home feeds but i also want to get Images displaying next to the Text ...
currently all i am getting is [URL] ....
So a am able to get the URL Link but getting that to a Image seems to be the problem
/ArrayLists
final ArrayList<String> TweetArray = new ArrayList<String>(); //Array List for Users Tweets..
final static ArrayList<String> incomingTweets = new ArrayList<String>(); //ArrayList for Incoming Tweets.
ArrayList<String> arrayImages = new ArrayList<String>();//ArrayList for incoming Tweet Profile Images
private Map<String, ImageIcon> imageMap;
[Code] ....
View Replies
View Related
Mar 27, 2014
The code below is just the GUI for a slot machine. Currently when play is clicked it displays the random number, I'm trying to make it so each random number displays an image in the GUI instead. For example if the random numbers were 2,2,3 it would display Cherry, Cherry, Bells. I started changing field1 to the image but realised I was on the wrong track as it would just display the same image not one allocated to a number. I've left in what I started doing.
how to do it?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SlotMachineGUI {
JPanel mainPanel;
SlotMachine slotEngine;
[code]....
View Replies
View Related
Dec 20, 2014
how to phrase the question. I created a small applet in java.. it allows me to move a toon around a blank applet window. I am using four gif files that have a walking animation in them. The issue i am having is after moving around the gif just flashes in and out really quickly.. when i start the program, moving up and down seems to be working perfectly fine, but the moment i move left or right it starts messing up for all directions. here is my code.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CharactorMove extends JApplet implements KeyListener
[code]....
View Replies
View Related
Oct 29, 2014
I am trying to drag the window down wards and screen has alignment issues. I tried to use WindowListeners, Component Listeners, MouseListeners ect…
But still this problem persists as only I release the mouse after drag down it appears fine that we have handled ComponentResized() method. So how to restrict component size while keep dragging down?
View Replies
View Related
Apr 9, 2014
I want to build a class that takes a JTable and previews on screen how it will be printed on the default printer. This is what we use to call as "Print Preview", just like MS Word, Excel, etc. As we already know Java does not support this functionality out-of-the-box.
Based on some examples I've found googling I built two classes. The first one TestPreview.java justs shows the JTable and the second one PrintPreview.java previews how the JTable will be printed on the printer.
I have two buttons to go through the pages, "PREV" and "NEXT" and "Print' button to print the JTable. My problem is that when my JTable has too many rows and spans in more than one page PrintPreview does not work. It shows the same page again and again. Also, it does not show the entire JTable data, but only some of them and I can't figure out why.
Below is my two classes.
TestPreview.java
package printpreviewdemo;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
[Code] ....
Below are my screenshots.
View Replies
View Related
Aug 12, 2014
I've got to make a ball bounce around a screen.... From what I can gather they seem to hold back useful java code.
anyway, i've changed the code over and over, and think this is the most succinct way i can manage it. but i have a problem. where i've marked the code (*****) and the following line are conditional on each other. so one won't provide the correct answer without the other line executing first, and vice versa (ignore the code after, i haven't looked at where that should be yet ). Anyway I don't really want to rip the code apart, again, because i'm pretty sure it's close.
View Replies
View Related
Feb 2, 2014
I attempted to make my square move in the screen and i set up collision with another object, however the graphics are flickering, really flickering, here's the code:
Java Code:
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class NewEmpty extends JFrame {
double p1speed =5, p2speed =5;
[code]....
View Replies
View Related
Aug 7, 2014
Is it possible to switch images (on jlabel)on combobox item select. I
If (combobox.selecteditem = value)
{
SetIcon (resource) // I'm using the default auto generated code used by eclipse when we set an icon for a jlabel in the gui
}
View Replies
View Related
Sep 26, 2014
I developed a swing application using group layout. It resizes when I resize the frame but when I change the screen resolution or when I run the application in a laptop which has small sized screen, the components over lap each other. I need my application to fit according to the screen resolution
The code is as follows
private void initComponents() {
jComboBox1 = new javax.swing.JComboBox();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
[Code]...
According to the list item selected, an internal frame will appear in the desktop pane. I use group layout for that internal frame too.
View Replies
View Related
Jul 16, 2014
I want to make swing form full screen even on taskbar on linux machine. But after trying so hard unable to achieve it. I am using fedora as operationg system.
Below i am giving you my swing code. but whenever i run this file form comes up on the screen and waits for a second and it goes in background.
I am using linux OS Fedora 64 bit.
public class ThankYou {
JFrame f;
JTextArea nameField;
JLabel lable;
String str;
[Code] ....
View Replies
View Related
Mar 30, 2015
I'm working on Ubuntu with resolution 1600*900; I used MigLayout to place the components of the application; but when I go with higher resolutions,components adjustment and alignment are not up to the mark.
View Replies
View Related
Mar 16, 2015
I'm making a game of checkers for my A2 Computing coursework which is due in within a week. I have completely finished the game, and only thing I have left to do is connect the two JPanels together via a CardLayout that I have made. However I am unsure how to do so
Here is the code from my CardLayout:
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;
[Code] ....
I have kept the code I am displaying to a minimal, hence I have removed all the action listeners for my buttons, anyway the problem I have is that, I would like it so that when the user clicks on the 'Multiplayer' button which is the array button ourButtons[1], it will then transition into my main game screen so that the user can then play a game of checkers.
Here is the main important GUI from my CheckerBoard class:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CheckerBoard extends JPanel implements ActionListener, MouseListener {
// Main routine that opens an Applet that shows a CheckerBoard
public static void main(String[] args) {
new CLayout();
[Code] ....
Once again kept to a minimal.
View Replies
View Related
Jun 21, 2014
Am trying to dynamically insert buttons (which will be presenting card in a frame) using grid layout.As shown image is getting inserted but its not fit in button.I tried Darryl's Stretch icon as well but of no support.
panel_playerCards.setLayout(new GridLayout(2,10, 0, 0));
for(int i=0;i<9;i++){
StretchIcon icon=new StretchIcon(UnoGui.class.getResource("/UnoColors/green/card10.png"));
btnArr[i].setIcon(icon);
btnArr[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
View Replies
View Related
Mar 27, 2014
I'm working on loading SVG images on Jpanel using "Apache(tm) Batik SVG Toolkit" , but after the image get loaded it has "white background" and "not transparent" one like PNG images.
I checked "fill" of rect attribute on the xml file of the svg image and it was correctly set to none, I also Tested the image on html document and it was trasparent, but in my java app it has white background.
The Question is there any way to load SVG images with transparent background on Jpanel ?
View Replies
View Related
Jul 17, 2014
I'm going through the next problem:
importing a project from Eclipse into NetBeans, I tried importing project, did not work, anyway
I got all the classes good, but I got a folder with images and a TXT file
part of the code:
listaIconsPlayers[0]=(IconsUtils.makeIcon("imagespinspin_blue.png",dimensaoPinGrande,"pin_blue"));
listaIconsPlayers[1]=(IconsUtils.makeIcon("imagespinspin_green.png",dimensaoPinGrande,"pin_green"));
listaIconsPlayers[2]=(IconsUtils.makeIcon("imagespinspin_purple.png",dimensaoPinGrande,"pin_purple"));
listaIconsPlayers[3]=(IconsUtils.makeIcon("imagespinspin_red.png",dimensaoPinGrande,"pin_red"));
listaIconsPlayers[4]=(IconsUtils.makeIcon("imagespinspin_yellow.png",dimensaoPinGrande,"pin_yellow"));
Where do I place my folder Images and how can I configure this so this lines of code go get that images from a folder inside the project..
View Replies
View Related
Jun 7, 2014
This is my class with the GUI:
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
[code]....
Eclipse error message:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:205)
at GUI.<init>(GUI.java:26)
at Apples.main(Apples.java:7)
i think the problem is to do with my images not being recognised. I put them in my source in User>...>workspace>src which is correct as far as i know. From what i know the images should show up if i look at my src file in eclipse but they dont. I tried changing the file type from .png to .jpg but it makes no difference.
View Replies
View Related