awt

Why does my icon handling code throw a NullPointerException?

自古美人都是妖i 提交于 2019-11-29 05:10:25
I have added an image for my button,but when I run that frame this exception will be thrown .why?please help me. init: deps-jar: compile-single: run-single: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(ImageIcon.java:138) at ClientGUI.IdAndPasswordFrame.initComponents(IdAndPasswordFrame.java:91) at ClientGUI.IdAndPasswordFrame.<init>(IdAndPasswordFrame.java:22) at ClientGUI.IdAndPasswordFrame$4.run(IdAndPasswordFrame.java:200) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) at java.awt.EventQueue.dispatchEvent

Export JPanel to vector graphics

丶灬走出姿态 提交于 2019-11-29 05:02:11
I would like to export the image in my JPanel to a vector graphics file so it can be edited and printed at a higher-than-screen resolution. Essentially I want its paint() function to be called with a destination Graphics that saves the drawing commands into a vector graphic file. What is a good, simple way to do this? What libraries are recommended? Which vector format would be best, and why? Pierre Have a look at The Java EPS Graphics2D package . Many Java programs use Graphics2D to draw stuff on the screen, and while it is easy to save the output as a png or jpeg file, it is a little harder

Java8 对 Map 排序

巧了我就是萌 提交于 2019-11-29 04:51:07
引言 使用 keys 或 values 对 map 排序。 1. 快速开始 步骤: 将 map 转为流 对流排序 收集并返回一个新的 LinkedHashMap (保持顺序) Map result = map.entrySet().stream() .sorted(Map.Entry.comparingByKey()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, LinkedHashMap::new)); 默认情况下,Collectors.toMap 将返回一个 HashMap。 2. 按 Keys 排序 public static void main(String[] args) { Map<String, Integer> unsortMap = new HashMap<>(); unsortMap.put("z", 10); unsortMap.put("b", 5); unsortMap.put("a", 6); unsortMap.put("c", 20); unsortMap.put("d", 1); unsortMap.put("e", 7); unsortMap.put("y", 8); unsortMap

Java - Draw a ruler (line with tick marks at 90 degree angle)

故事扮演 提交于 2019-11-29 04:27:01
I'm using Java AWT to draw lines on a panel ( Line2D and Graphics2D.drawLine() ) and I'm wondering how I can draw a line with tick marks, similar to: |----|----|----|----|----| I know the positions I'd like to draw the ticks at in advance. The lines could be in any position, so the ticks must be drawn at an angle releative to the line itself. My basic geometry & ability to apply it in Java is failing me. :) I suggest you implement a ruler-drawing-method that draws a simple horizontal ruler from left to right Figure out the desired angle using Math.atan2 . Apply an AffineTransform with

Cannot load font in JRE 8

坚强是说给别人听的谎言 提交于 2019-11-29 04:15:02
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 thread "main" java.io.IOException: Problem reading font data. at java.awt.Font.createFont0(Font.java:1000) at java.awt.Font.createFont(Font.java:877) at Main$.delayedEndpoint$Main$1(Main.scala:31) at Main$delayedInit$body.apply(Main.scala:11)

Differences between components and lightweight/heavyweight

荒凉一梦 提交于 2019-11-29 03:59:09
What is the difference between JPanel and JFrame and relationship to lightweight, heavyweight? JPanel is container that allows to put several UI components together. JFrame is a window written using Swing. All Swing components are so-called "lightwight" components because they are written in java. If for example you run Swing application and try to analyze it using UI analyzing tool (e.g. WinSpy in windows) you see only one element: the window (JFrame) itself. All other components are drawn from OS point of view. Heavyweight API - AWT uses portable elements provided by OS. Since java must be

Create an image from a non-visible AWT Component?

二次信任 提交于 2019-11-29 03:02:51
I'm trying to create an image (screen-shot) of a non-visible AWT component. I can't use the Robot classes' screen capture functionality because the component is not visible on the screen. Trying to use the following code: BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); component.paintAll(g); Works sometimes, but does not work if the component contains things such as a text box or button, or some sort of OpenGL / 3D component (these things are left out of the image!). How can I take a proper screenshot of the whole thing

ActionListener for JLabel

≡放荡痞女 提交于 2019-11-29 02:20:43
I want to learn how to write an ActionListener for JLabel . I want to make a label that open a new frame for user when user clicks the label. Maybe MouseListener can work but I do not know how to make it. I recommend using a JTextField rather than a JLabel for this use. Being based on a component designed to be focusable, it allows an ActionListener and looks and feels more like an HTML link. E.G. That is how it appears when the mouse is hovering over the first link. LinkLabel /* License - LGPL LinkLabel Using the Desktop Class There are a lot of link labels. This one uses the Java 1.6+

Why bother with setting the “sun.awt.exception.handler” property?

╄→尐↘猪︶ㄣ 提交于 2019-11-29 02:17:18
Here's some code that catches an exception thrown on the Event Dispatch Thread: package com.ndh.swingjunk; import java.awt.EventQueue; import javax.swing.JFrame; public class EntryPoint { public static void main(String[] args) { Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler()); // System.setProperty("sun.awt.exception.handler", MyExceptionHandler.class.getName()); EventQueue.invokeLater(new Runnable() { public void run() { new SomeWindow("foo").setVisible(true); } }); } } class SomeWindow extends JFrame { public SomeWindow(String title) { this.setTitle(title); this

How can I do full screen in Java on OSX

你。 提交于 2019-11-28 23:47:39
I've been trying and failing to use the java full screen mode on the primary display of an OSX system. Whatever I've tried I can't seem to get rid of the 'apple' menu bar from the top of the display. I really need to paint over the entire screen. Can anyone tell me how to get rid of the menu? I've attached an example class which exhibits the problem - on my system the menu is still visible where I would expect to see a completely blank screen. import java.awt.*; import java.awt.event.*; import javax.swing.JFrame; public class FullScreenFrame extends JFrame implements KeyListener { public