Java Code Examples for javax.swing.JPanel#getHeight()
The following examples show how to use
javax.swing.JPanel#getHeight() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: triplea File: ResourceImageFactory.java License: GNU General Public License v3.0 | 6 votes |
/** * Returns button with resource amounts and given text. If resources is empty then returns button * with just the text. */ public JButton getResourcesButton(final ResourceCollection resources, final String text) { if (resources.isEmpty()) { return new JButton(text); } final JPanel panel = getResourcesPanel(resources); panel.setOpaque(false); panel.add(new JLabel(text)); panel.setSize(panel.getPreferredSize()); panel.doLayout(); final BufferedImage image = new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics2D g = image.createGraphics(); panel.paint(g); g.dispose(); return new JButton(new ImageIcon(image)); }
Example 2
Source Project: swcv File: WordCloudMenuBar.java License: MIT License | 6 votes |
private void exportPNG(final JPanel panel, String selectedFile) { BufferedImage img = new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D g2d = img.createGraphics(); panel.printAll(g2d); g2d.dispose(); try { ImageIO.write(img, "png", new File(selectedFile)); } catch (IOException ex) { ex.printStackTrace(); } }
Example 3
Source Project: CyberBiology File: ViewBasic.java License: GNU General Public License v3.0 | 5 votes |
public Image paint(World world,JPanel canvas) { int w = canvas.getWidth(); int h = canvas.getHeight(); //Создаем временный буфер для рисования Image buf = canvas.createImage(w, h); //подеменяем графику на временный буфер Graphics g = buf.getGraphics(); g.drawRect(0, 0, world.width * World.BOTW + 1, world.height * World.BOTH + 1); world.population = 0; world.organic = 0; for (int y = 0; y < world.height; y++) { for (int x = 0; x < world.width; x++) { if (world.matrix[x][y] == null) { g.setColor(Color.WHITE); g.fillRect(x * World.BOTW,y * World.BOTH, World.BOTW, World.BOTH); } else if ((world.matrix[x][y].alive == 1) || (world.matrix[x][y].alive == 2)) { g.setColor(new Color(200, 200, 200)); g.fillRect(x * World.BOTW, y * World.BOTH, World.BOTW, World.BOTH); world.organic = world.organic + 1; } else if (world.matrix[x][y].alive == 3) { g.setColor(Color.BLACK); g.drawRect(x * World.BOTW, y * World.BOTH, World.BOTW, World.BOTH); // g.setColor(new Color(matrix[x][y].c_red, matrix[x][y].c_green, matrix[x][y].c_blue)); int green = (int) (world.matrix[x][y].c_green - ((world.matrix[x][y].c_green * world.matrix[x][y].health) / 2000)); if (green < 0) green = 0; if (green > 255) green = 255; int blue = (int) (world.matrix[x][y].c_blue * 0.8 - ((world.matrix[x][y].c_blue * world.matrix[x][y].mineral) / 2000)); g.setColor(new Color(world.matrix[x][y].c_red, green, blue)); // g.setColor(new Color(matrix[x][y].c_red, matrix[x][y].c_green, matrix[x][y].c_blue)); g.fillRect(x * World.BOTW + 1, y * World.BOTH + 1,World.BOTW-1, World.BOTH-1); world.population = world.population + 1; } } } return buf; }
Example 4
Source Project: pumpernickel File: PumpernickelShowcaseApp.java License: MIT License | 5 votes |
/** * Capture a screenshot based on the position of the given panel. * <p> * This uses a Robot to actually capture the real screenshot in case other * floating layers/windows are meant to be captured. */ private BufferedImage getScreenshot(JPanel panel) throws Exception { Robot robot = new Robot(); Point p = panel.getLocationOnScreen(); Rectangle screenRect = new Rectangle(p.x, p.y, panel.getWidth(), panel.getHeight()); return robot.createScreenCapture(screenRect); }
Example 5
Source Project: pumpernickel File: QPanelUI.java License: MIT License | 5 votes |
private Outline getOutline(JPanel c, boolean ideal) { String key = ideal ? PROPERTY_CACHED_SCRATCH_OUTLINE : PROPERTY_CACHED_REAL_OUTLINE; Outline outline = (Outline) c.getClientProperty(key); int effectiveWidth = ideal ? 1000 : c.getWidth(); int effectiveHeight = ideal ? 1000 : c.getHeight(); if (outline == null || !outline.isValid(effectiveWidth, effectiveHeight)) { outline = new Outline(effectiveWidth, effectiveHeight); c.putClientProperty(key, outline); } return outline; }
Example 6
Source Project: SciGraph File: ImageWriter.java License: Apache License 2.0 | 5 votes |
private static BufferedImage renderImage(JPanel panel) { JFrame frame = new JFrame(); frame.setUndecorated(true); frame.getContentPane().add(panel); frame.pack(); BufferedImage bi = new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = bi.createGraphics(); panel.print(graphics); graphics.dispose(); frame.dispose(); return bi; }
Example 7
Source Project: CyberBiology File: ViewMultiCell.java License: GNU General Public License v3.0 | 4 votes |
public Image paint(World world,JPanel canvas) { int w = canvas.getWidth(); int h = canvas.getHeight(); //Создаем временный буфер для рисования Image buf = canvas.createImage(w, h); //подеменяем графику на временный буфер Graphics g = buf.getGraphics(); g.drawRect(0, 0, world.width * World.BOTW + 1, world.height * 4 + 1); world.population = 0; world.organic = 0; for (int y = 0; y < world.height; y++) { for (int x = 0; x < world.width; x++) { if (world.matrix[x][y] == null) { g.setColor(Color.WHITE); g.fillRect(x * World.BOTW,y * World.BOTH, World.BOTW, World.BOTH); } else if ((world.matrix[x][y].alive == 1) || (world.matrix[x][y].alive == 2)) { g.setColor(new Color(200, 200, 200)); g.fillRect(x * World.BOTW, y * World.BOTH, World.BOTW, World.BOTH); world.organic = world.organic + 1; } else if (world.matrix[x][y].alive == 3) { g.setColor(Color.BLACK); g.drawRect(x * World.BOTW, y * World.BOTH, World.BOTW, World.BOTH); switch(world.matrix[x][y].isMulti()) { case 1:// - есть MPREV, g.setColor(Color.MAGENTA); g.fillRect(x * World.BOTW + 1, y * World.BOTH + 1, World.BOTW-1, World.BOTH-1); break; case 2:// - есть MNEXT, g.setColor(Color.BLACK); g.fillRect(x * World.BOTW + 1, y * World.BOTH + 1, World.BOTW-1, World.BOTH-1); break; case 3:// есть MPREV и MNEXT g.setColor(Color.MAGENTA); g.fillRect(x * World.BOTW + 1, y * World.BOTH + 1, World.BOTW-1, World.BOTH-1); break; default: int green = (int) (world.matrix[x][y].c_green - ((world.matrix[x][y].c_green * world.matrix[x][y].health) / 2000)); if (green < 0) green = 0; if (green > 255) green = 255; int blue = (int) (world.matrix[x][y].c_blue * 0.8 - ((world.matrix[x][y].c_blue * world.matrix[x][y].mineral) / 2000)); g.setColor(new Color(world.matrix[x][y].c_red, green, blue)); g.fillRect(x * World.BOTW + 1, y * World.BOTH + 1, World.BOTW-1, World.BOTH-1); break; } world.population = world.population + 1; } } } return buf; }
Example 8
Source Project: jdk8u_jdk File: DrawTest.java License: GNU General Public License v2.0 | 4 votes |
static private BufferedImage getScreenShot(JPanel panel) { BufferedImage bi = new BufferedImage( panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_ARGB); panel.paint(bi.getGraphics()); return bi; }
Example 9
Source Project: jts File: RenderManager.java License: GNU Lesser General Public License v2.1 | 4 votes |
private Image createPanelImage(JPanel panel) { return new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_ARGB); }