awt

Drawing a Component to BufferedImage causes display corruption

时光毁灭记忆、已成空白 提交于 2019-11-26 19:11:41
I am using the JScrollNavigator component described here , in order to provide a navigation window onto a large "canvas-like" CAD component I have embedded within a JScrollPane . I have tried to adapt the JScrollNavigator to draw a thumbnail image of the canvas to provide some additional context to the user. However, the action of doing this causes the rendering of my application's main frame to become corrupted. Specifically, it is the action of calling paint(Graphics) on the viewport component (i.e. my main canvas), passing in the Graphics object created by the BufferedImage that causes

get width and height of JPanel outside of the class

若如初见. 提交于 2019-11-26 18:43:16
问题 So I created a simple simple simulation where squares are spawned randomly with random vectors and bounce of the edges of the window. I wanted it to take into account the window being resized. So that if I change the dimensions of the window from 600x600 to 1200x600 the squares will bounce of the new border rather than 600x600. I tried doing getWidth() getHeight() but it would return 0. So I put it in the pain() (since it gets called on window resize) method and saved the return values as

Splash Screen Progress bar not drawing

徘徊边缘 提交于 2019-11-26 18:39:44
问题 I'm trying to make my own progress bar, on my splash screen. Creating my splash screen was easy: java -splash:EaseMailMain.jpg Main.class (From Eclipse) The first line of my main method calls this: new Thread(new Splash()).start(); And this is the splash class: public class Splash implements Runnable { public volatile static int percent = 0; @Override public void run() { System.out.println("Start"); final SplashScreen splash = SplashScreen.getSplashScreen(); if (splash == null) { System.out

java buffered image created with red mask

天大地大妈咪最大 提交于 2019-11-26 18:35:30
问题 I am having trouble reading an image. If I do the following URL url = new URL("http://tctechcrunch2011.files.wordpress.com/2012/10/gmm.jpg"); ImageInputStream stream = ImageIO.createImageInputStream(url.openStream()); ImageReader reader = ImageIO.getImageReaders(stream).next(); reader.setInput(stream, true, true); BufferedImage image = reader.read(0); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ImageWriter writer = ImageIO.getImageWritersByFormatName("JPEG").next();

Why is paint()/paintComponent() never called?

淺唱寂寞╮ 提交于 2019-11-26 18:29:11
问题 For the last two days I have tried to understand how Java handles graphics, but have failed miserably at just that. My main problem is understanding exactly how and when paint() (or the newer paintComponent() ) is/should be called. In the following code I made to see when things are created, the paintComponent() is never called, unless I manually add a call to it myself or calls to JFrame.paintAll()/JFrame.paintComponents(). I renamed the paint() method to paintComponent() in hoping that

Add WebView control on Swing JFrame

非 Y 不嫁゛ 提交于 2019-11-26 18:18:35
问题 I am working on Swing application mixed with JavaFX control. I have created a JavaFX control ( WebView ) to browse HTML files. But I want to know, how can I add this web view control on the container of a Swing JFrame ? 回答1: Given an already existing jFrame , the following code adds a new WebView and loads a URL: // You should execute this part on the Event Dispatch Thread // because it modifies a Swing component JFXPanel jfxPanel = new JFXPanel(); jFrame.add(jfxPanel); // Creation of scene

A rotated square panel in Java GUI

心不动则不痛 提交于 2019-11-26 17:59:13
I wonder if it is possible to implement a GUI panel (possibly JPanel) that is of square shape but rotated 90 degrees. Obviously, there will be a top-level container which contains this panel, and visually the main panel is this rotated square panel within. More specifically, I would divide a panel (called 'A') into 4 equal square sub-panels, and fill these sub-panels with JLabels, for which I am thinking to use GridLayout. And lastly, I would rotate 'A' 90 degrees to give what I want. From my reading of other similar questions, it seems that you cannot rotate JPanel itself, but you can rotate

Is this the correct way of using Java 2D Graphics API?

十年热恋 提交于 2019-11-26 17:52:50
问题 I'm creating a graphical front-end for a JBox2D simulation. The simulation runs incrementally, and in between the updates, the contents of the simulation are supposed to be drawn. Similar to a game except without input. I only need geometric primitives to draw a JBox2D simulation. This API seemed like the simplest choice, but its design is a bit confusing. Currently I have one class called Window extending JFrame , that contains as a member another class called Renderer . The Window class

zoom using mouse and graphics

折月煮酒 提交于 2019-11-26 17:49:37
问题 I draw in my JComponent some curves, etc .. with Graphics G ( not 2D ). Now I want to use the scroll wheel of my mouse to zoom in and out. Any tracks ? I heard talk about a BuferredImage ? 回答1: There are a few considerations you need to take into account... The end result will depend on what you want to achieve. If you are drawing curves using the Graphics2D API, it might be simpler to simply scale the coordinates each time the component is rendered. You will need to make sure that any

JavaFX screencapture headless exception on OSX

无人久伴 提交于 2019-11-26 17:49:12
问题 I'm converting my old java app from swing to javafx and I'm running into a problem. I'm using the following code to capture screenshots: public ScreenCapper() { ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); gs = ge.getScreenDevices(); try { robot = new Robot(gs[gs.length-1]); } catch (AWTException e) { LOGGER.getInstance().ERROR("Error creating screenshot robot instance!"); } } public Color capture() { Rectangle bounds; mode = gs[0].getDisplayMode(); bounds = new Rectangle(0, 0,