jpanel

Java transparent panels & custom effect on panels

走远了吗. 提交于 2019-11-27 06:21:54
问题 I want to have transparent panels in my GUI (if like Windows 7 window headers, it is better). Before I have used com.sun.awt.AWTUtilities as AWTUtilities.setWindowOpacity(frame, (float)0.90); but its parameter is a window like JFrame and couldn't be used for JPanel . Also I want to have effects on JPanel or JLabel for example luminescence, as is on Windows 7 header buttons. Any other interesting effect is also helpful for me. 回答1: Please see the tutorials How to Create Translucent and Shaped

How to get the color of a point in a JPanel? [closed]

早过忘川 提交于 2019-11-27 06:17:07
问题 By knowing the coordinates of a point in a JPanel, how can I get its color? 回答1: Draw the content of the panel inside a Graphics2D object created from a BufferedImage and then retrieve the pixel color: BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D g2 = image.createGraphics(); _mainPanel.paint(g2); image.getColorModel().getRGB(pixel); g2.dispose(); 来源: https://stackoverflow.com/questions/13307962/how-to-get-the-color-of-a-point-in-a-jpanel

Is there any way I can rotate this 90 degrees?

徘徊边缘 提交于 2019-11-27 05:41:08
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"; createTimer(); timer.start(); } private void createTimer(){ timer = new Timer(0, new ActionListener() {

Java Container remove method not working correctly

可紊 提交于 2019-11-27 05:39:08
i hava added 1.TextArea 2.TextField then i start adding JButton successively on container...,now by using JRadioButton i want to remove JButton from container using this code i=0; k=0; while(!birdButton[i].isSelected()){ i++; } System.out.println(i); k=i+2; list.removeElementAt(i); listName.removeElementAt(i); System.out.println(k); c.getContentPane().remove(k); but when i select the 1st radiobutton 1st JButton should be deleted because of k=i+2; instead of deleting this one it deletes the TextArea(1st one). when i select the 3rd radiobutton then 1st JButton is deleted. can anyone let me know

Slide JPanel Content in a JForm on Java

拥有回忆 提交于 2019-11-27 05:13:40
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(); jpanelprincipal1.setSize(panel1width -- , panel2height --); jpanelprincipal2.setSize(440,250); } I used this trick in

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

老子叫甜甜 提交于 2019-11-27 05:02:54
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.png")); } catch (IOException e) { } Graphics g = img.getGraphics(); g.drawImage(img,0, 0,

How to include custom panel with NetBeans GUI Builder?

喜你入骨 提交于 2019-11-27 05:00:19
I have written a class that extends JPanel. Is it possible to use this in the NetBeans GUI Builder and have it survive all of the automatic code generation? I have used the customised code option in the GUI builder to instantiate the object as the new class, but it seems like the declaration can't be changed from JPanel, so only methods that I have overridden get called, I can't call new ones that are not present in JPanel. Curyous Simply drag the class from the projects tree on to the form in the GUI designer. Just like it says in stackoverflow question 691890 . You can use the Palette

Fit image into the printing area

此生再无相见时 提交于 2019-11-27 04:53:02
问题 I need to print images in Java. So I implemented print() method of Printable interface. But printer always prints only some piece of original image. How I can cause image to fit printing area (A4), so printer be able to print whole image, not piece of them? Now my code looks like this: public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { if (pageIndex >= images.size()) { return Printable.NO_SUCH_PAGE; } RenderedImage image; Graphics2D graphics2D

JPanel image flies from the screen

痴心易碎 提交于 2019-11-27 04:52:42
问题 I'm trying to make my Pedestrian object move, and it moves but at a certain point it flies away from the screen. The Pedestrian moves by a List of points. First the Pedestrian is added to toDraw to paint it and in startAndCreateTimer I loop through the same list to move the Vehicles Maybe it's because of this line i = (double) diff / (double) playTime; I actually don't want to set a playtime how not to do that, could this be the problem or is it something else? Here a link with the point

Incorrect behavior of JPanel#paintChildren(Graphics) when a JMenu is present?

妖精的绣舞 提交于 2019-11-27 04:43:40
问题 What I want to do: Create a JPanel 's subclass to draw a simple overlay on top of contained components. Why don't I use JLayeredPane ? See JComponent#isOptimizedDrawingEnabled() . When a JMenu is present in a JFrame , adding a JPanel with an overridden paintChildren(Graphics) method, an incorrect coordinate starting point is provided in the passed Graphics object, as observed with this code sample: import java.awt.Color; import java.awt.FontMetrics; import java.awt.Graphics; import javax