jpanel

Image resizing and displaying in a JPanel or a JLabel without loss of quality

南笙酒味 提交于 2019-11-26 12:31:23
问题 I\'m developing a java program to capture employee images at the time of registration using a webcam. I can obtain the picture without any problem, and save it in my C: drive but upon retrieval of the image only a part of the image is displayed on the label. Is there a way of re sizing the JPEG before saving it? or before displaying it? like shrinking it without a quality loss.... Thankz a lot Cheerz! :)! okay guys... here goes:- I have commented the code in the way I have used them. //This

How to repaint a JPanel after have drawn on it?

倖福魔咒の 提交于 2019-11-26 12:31:15
问题 I have a component that inherits from JPanel, I draw a grid on it. Now I have a JComboBox and I want the user to be able to choose the grid size here and then press a button to make the grid change (repaint the grid). The thing is that it paints the initial grid, but once the user choses a grid size from the JComboBox and clicks the button, nothing happens. I have to minimize the form and then restore it again to see the changes. Any Ideas? The Code is below. The Component: public class Board

Is there any way I can rotate this 90 degrees?

孤街醉人 提交于 2019-11-26 11:40:33
问题 This is my current code: package Calendar; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.SimpleDateFormat; import java.util.Date; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.Timer; public class Clock extends JLabel { private String pattern; private Timer timer; public Clock(String pattern){ this.pattern = pattern; createTimer(); timer.start(); } public Clock(){ pattern = \"hh:mm:ss a\";

Slide JPanel Content in a JForm on Java

这一生的挚爱 提交于 2019-11-26 11:28:18
问题 I have a question. I want to make a swing form that, when clicking in a button he slides a panel (with his content) to the left so the panel on the right replaces it with a smooth effect. I Have tried to do a while how checks the size of the panel and then minimize it and shows the next one like this : while (jpanelprincipal1.getWidth() < 439 || jpanelprincipal1.getHeight() > 250) { int panel1width = jpanelprincipal1.getWidth(); int panel2height = jpanelprincipal1.getHeight();

Infinite background for game

蹲街弑〆低调 提交于 2019-11-26 11:28:04
问题 I am working on a Java project to simulate the flight of a helicopter in a frame. The helicopter moves on the screen using the arrow keys. I want the helicopter to be able to move infinitely, that is, when the helicopter reaches the edge of the frame, the background should move in the opposite direction to have the effect of endless terrain. Here is the code I have so far: import java.awt.Graphics; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.image

How do I draw an image to a JPanel or JFrame?

断了今生、忘了曾经 提交于 2019-11-26 11:25:48
问题 How do I draw an Image to a JPanel or JFrame, I have already read oracle\'s tutorial on this but I can\'t seem to get it right. I need the image \" BeachRoad.png \" to be displayed on a specific set of coordinates. Here is what I have so far. public class Level1 extends JFrame implements ActionListener { static JLayeredPane EverythingButPlayer; static Level1 l1; public Level1() { EverythingButPlayer = new JLayeredPane(); BufferedImage img = null; try { img = ImageIO.read(new File(\"BeachRoad

JPanel & components change position automatically

[亡魂溺海] 提交于 2019-11-26 11:25:24
Hi I am working on swing application but I am facing one problem. When I first run application JPanel is positioned at proper position where I decided to set with components inside. But problem occur when I minimize & again maximize frame window jpanel automatically changes it's position. Below images shows that difference As we can see on second image components changes it's position automatically. For this I written below code, jpanel_addPurchase = new JPanel(); jpanel_addPurchase.setLayout(null); jpanel_addPurchase.setBounds(400, 0, 500, 500); jpanel_addPurchase.setBackground(Color.white);

Java Swing - how to show a panel on top of another panel?

那年仲夏 提交于 2019-11-26 10:58:04
问题 I wish to have an internal (non window) dialog to ask for member input. I would like the dialog to be placed centrally on an existing JPanel. I have looked at layeredpanes and these seem unusable due to only having a single layout manager (or no layout manager) across all the panes. I guess I could try to override JLayeredPane and provide a custom layout but this seems extreme. Glass panes don\'t seem to be appropriate either. How can this be done? Is there no usable concept of z-indexes in

JPanel doesn&#39;t update when adding Component in another class

a 夏天 提交于 2019-11-26 10:03:28
问题 I\'m fairly new to Java Swing and I\'m running into a few problems. As a side question, when making a fairly large Java Swing Application, what is the best way to split up code? In my case I want to have an application that has a layout just as Microsoft Word where there is a JToolBar filled with buttons and a main JPanel where changes are made based on the buttons pressed in the Tool Bar. So as shown in the code below, I have a JFrame and I call the MainPanel class in order to create a panel

FlowLayout on top of GridLayout not working

岁酱吖の 提交于 2019-11-26 10:02:23
问题 I\'m trying to create a hangman game and so far it\'s coming along GREAT, but the layout design just doesn\'t seem to fall into place! The alphabet is supposed to end up in a FlowLayout order on top of the Hangman picture with the buttons \"Restart\", \"Help\" \"Add New Word\" and \"Exit\" at the bottom! What am I doing wrong? import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; public class Hangman extends JFrame { int i = 0; static JPanel panel; static JPanel