jcomponent

How do I get the image paint/paintComponent generates?

Hey guys. I have a quick question. How do I get the image generated by a JComponent.paint or paintComponent? I have a JComponent which I use as a 'workspace' and where I have overwritten the paintComponent method to my own. The thing is that my workspace JComponent also has children which has their own paintComponent methods. So when ...

Java get JPanel Components

I have a JPanel full of JTextFields... for (int i=0; i<maxPoints; i++) { JTextField textField = new JTextField(); points.add(textField); } How do I later get the JTextFields in that JPanel? Like if I want their values with TextField.getText(); Thanks ...

How to create a custom Swing Component

I've always wanted to create custom components in Java, or customize existing ones, but my searches never resulted in anything useful. So I decided to ask the StackOverflow community: Where can I find information about customizing Java GUI Components in general? And when I mean customizing, I'm not talking about changing colors, fonts ...

using a custom Swing JComponent in a TableCellRenderer

OK, I know how to make a simple custom JComponent. I know how to override a TableCellRenderer. I can't seem to combine the two. Here's a sample JComponent I created: public static class BarRenderer extends JComponent { final private double xmin; final private double xmax; private double xval; public BarRenderer(double xmin, double ...

Save drawing in JComponent into Tiff file

How to save drawing in JComponent into tiff format? I only know how to save the whole Java file but I dont know how to save specific Jcomponent. Help me :-( EDITED: Thanks guys, now I am able to save my drawing to Jpeg. However I just wanted to save one of the component? The c.paintAll(bufferedImage.getGraphics()); seem to save the wh...

Basic animation in Java for a screensaver app of sorts

I was assigned to make an animated screensaver as a programming project for my Advanced Programming course. The objective is to have several moving components inside an undecorated, fullscreen frame, but I'm going step-by-step and doing it one component at a time. Here's my source code so far: http://pastebin.com/dc722188 Feel free to...

JComponent and Left Align of components

With the following code, I want to create a Jpanel generic component and add two sub components, a Label and a JTextField. I am to add the components, but they do not left align. (No, I don't need GridBagLayout, but I was trying to do a basic example with GridBag. Can you describe how to do this with GridBag and not another layout). ...

Using Java's JComponent repaint()

Hi there, I'm writing a simple Game of Life program in Java and am having a bit of trouble getting it to animate. I've got a JComponent class LifeDraw, which displays a grid of pixels, with the following paint method: protected void paintComponent(Graphics g) { super.paintComponent(g); for (int y = 0; y < lGrid.getHeight(); y+...

Custom Drawn Component Not Drawing Inside JScrollPane

Hi all, I was using Java JRE 1.6.7 and had a JComponent and a JScrollPane. I couldn't get double buffering to work on this which always resulted in a flicker. I had the buffering taken care of if I used a Canvas, but this resulted in problems when used in conjunction with a JScrollPane. So I downloaded JRE 1.6.18 in hopes that one of ...

JComponent: How can it resist smallification?

I have a custom JComponent that paints some stuff when paint is called. In a Border layout, though, it's minimumSize is not being respected. I've included this @Override public Dimension getMinimumSize() { System.out.println("asking for min size"); return MINIMUM_SIZE; } and it never gets called. I've also tried setting min si...

Resize JComponent for file export

I have a JPanel upon which I draw a number of custom-written JComponents using the usual 'paintComponent(Graphics g)' method. I use a JLayeredPane to control the display order of the custom components, as follows: public Class MyPanel extends JPanel { private JLayeredPane layeredPane = new JLayeredPane(); private JComponent com...

Java JComponent Scrollable resetting position.

I have a a JPanel with a BorderLayout() BorderLayout.CENTER contains a JComponent which implements scrollable And the north contains a JLabel, when ever I call setText() on the JLabel, the positioning of the JComponent resets back to the default position, of viewing the top left point? Are there methods to get around this, I have had a ...

Custom JComponent not displaying in Custom JPanel

I've tried the add() method but nothing is displayed when I try to add Test to GraphicsTest. How should I be adding it? Can someone show me? I've included the code I'm using. This is my way and it's not working. Can someone show me or make me aware of what the problem actually is? import java.awt.Color; import java.awt.Graphics; import...

JComponent undock effect

I'm trying to accomplish an undock effect for a custom Swing JComponent. By default the component is used inside a form along with other components. I want to be able to maximize this component to use the whole screen and then be able to dock it again. So far I've tested public void showDialog() { JFrame mainFrame = App.getAppl...

How do I get a JComponent to resize after calling `setVisible(true)`?

Our application displays a 2D view of our data (mainly maps) and then allows the user to change to a 3D view. The 2D and 3D views are generated by custom C++ code that is SWIG'ed into our Swing GUI and wrapped within a JComponent. These JComponents are then displayed within another parent JComponent. Our problem is that when we change f...

JFrame that has multiple layers

Hello, I have a window that has two layers: a static background and a foreground that contains moving objects. My idea is to draw the background just once (because it's not going to change), so I make the changing panel transparent and add it on top of the static background. Here is the code for this: public static void main(String[] a...

Help with rendering the Mandelbrot set in Java

I wrote an implementation of the Mandelbrot set in Java using a JComponent but I'm getting strange results when I render it. Besides that everything compiles right. I'm just not for sure what I'm doing wrong with it. Any code review also would be appreciated. My source is posted on pastebin since it would take up too much room here: JM...

Java/Swing offscreen rendering (Cobra HTMLPanel -> BufferedImage) Problem: Component doesn't finish redrawing first

I'm trying to render the contents of a the Java/Swing Cobra HTML renderer to an offscreen BufferedImage, for use elsewhere in my app: slideViewPanel.setDocument(document, rendererContext); BufferedImage test = new BufferedImage(300,300,BufferedImage.TYPE_INT_RGB); Graphics g = test.getGraphics(); slideViewPanel.paint(g); The resul...

JPanel not listening to key event when there is a child component with JButton on it

I'm working on a map editor for my college project. And I had a problem that the map panel is not listening key event while it should. This happens when I add a ToolBarPane (which extends JPanel) with JComponent such as JButton, JComboBox that implements ActionListener on it AND the map panel (which extends the JPanel) together on to the...

Manually position JComponent inside JPanel

I want to programmatically move my JLabel to a specific location inside my JPanel. I have tried setLocation(int x, int y), but it doesn't work. I am trying to not use any layout manager. ...