Questions tagged [jcomponent]

JComponent is the base class for all Java Swing components except top-level containers.

JComponent is the base class for all Java Swing components except top-level containers which descend from Window instead.

To use a component that inherits from JComponent, you must place the component in a containment hierarchy whose root is a top-level Swing container. Top-level Swing containers -- such as JFrame, JDialog, and JApplet -- are specialized components that provide a place for other Swing components to paint themselves.

768 questions
2
votes
1 answer

Java JComponent - start painting from lower left corner?

I'm overriding the paintComponent method for a background in a JComponent and all is going well. However, I want to start painting from the lower left corner instead of the upper left. Do I need to transform something, or what?
Ben
  • 54,723
  • 49
  • 178
  • 224
2
votes
3 answers

Java - Reusable button action handler concepts question

First off - sorry for the wall of code but it's not too horrendous, just a framework for what I'm trying to explain. It runs without errors. The goal I'm making a reuseable button class for my GUI and each button object needs to have a different…
Ben
  • 54,723
  • 49
  • 178
  • 224
2
votes
1 answer

Remove JPanel with some JComponents from JDialog

if created a JPanel and then added some JComponents with these rules public class MyPanel extends JPanel { myButton = new MyButton() myButton.addXxxListener(...) myButton .... add(myButton) } public class MyButton extends JButton { …
mKorbel
  • 109,525
  • 20
  • 134
  • 319
2
votes
3 answers

is it possible to have multiple JOptionPane dialogs?

does anyone know how do we have a JOptionPane dialog above another JOptionPane dialog?
Pacerier
  • 86,231
  • 106
  • 366
  • 634
2
votes
2 answers

How to repaint JComponent once after several repaint()?

My program loops on a list of JButton. For each JButton, it repaints it each second: public class a { static JFrame frame = new JFrame(); static Set components = new HashSet(); public static void main(String[] args)…
Skartt
  • 551
  • 2
  • 7
  • 19
2
votes
2 answers

Jslider reflected in pannel

I don't know why, although I am trying to make a color picker and for some reason the slider gets reflected in the panel, if I use one of the sliders and resize the frame the thing disappears. Here is what I see: I tried to change how different…
Brain Bytes
  • 121
  • 1
  • 12
2
votes
1 answer

Problem with extending class JLabel to add to it property dragging

I have class JLabelExtended, which extends class javax.swing.JLabel. I extend it, because I want to add property dragging using mouse. Here is my code: public class JLabelExtended extends JLabel { private MouseMotionAdapter…
evgeniy44
  • 2,862
  • 7
  • 28
  • 51
2
votes
1 answer

Get all listeners from javax.swing.text.Document instances

I have a JTextField instance with DocumentListener registered. I'd like to remove the documentListener using this method : jTextField.getDocument().removeDocumentListener(arg0) The issue I am running into, is that I can't access the document…
TheByeByeMan
  • 1,396
  • 2
  • 28
  • 50
2
votes
1 answer

Using paintComponent() on a JFrame canvas being altered by a separate GUI

I am trying to make a JComponent application which uses two JFrames, one frame with alterable sliders and textfields for the graphical display of a firework on the second. When the "fire" button is pressed, a rendering of the firework should appear.…
Joe Smith
  • 23
  • 3
2
votes
2 answers

How to get a copy of a JComponent?

I have a javax.swing.JButton which I have created to sign out. How can I get an exact copy(duplicate) of the button to another JFrame? private JButton signOut; public JButton getBtn(){ //Any idea? } return signOut; is not an option,…
Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80
2
votes
3 answers

Prevent Java from repainting the content of a JPanel while updating

I have a JPanel which contains a lot of child components. While updating\adding new components to the parent JPanel I'd like to prevent it from repainting, how can this achieved?
Viktor Sehr
  • 12,825
  • 5
  • 58
  • 90
2
votes
2 answers

JavaFX - Components are null when initializing Controller

Main class : Parent root = FXMLLoader.load(getClass().getResource("../layouts/main_window.fxml")); primaryStage.setTitle("IMGManager"); primaryStage.setScene(new Scene(root)); primaryStage.show(); FXML :
Bird
  • 572
  • 5
  • 15
2
votes
1 answer

Java Swing : Create a Grid of custom JComponents with padding

I'm trying to create a grid of customs JComponents. I want the grid being resizable without deform on my JComponent. But I am only able to get a grid with clipped JComponent and bad resizing. What I get : What I want : Here is my code : import…
Slynus
  • 35
  • 7
2
votes
1 answer

How do I fill a spanning area with a background colour In MigLayout?

This is a screenshot of my current interface: My JLabel targetJlabel is contained by a rectangle of property spany 2 with a red dotted border (I think, the rectangle is called a JComponent?), and I'd like to fill all of that rectangle with a…
Jamie Birch
  • 5,839
  • 1
  • 46
  • 60
2
votes
1 answer

how getHeight() works in java especially in paintComponent

When I google this method. It shows that it returns the height of the current component. I got confused because when I use this getHeight() in public void paintComponent(Graphics g) it returns the value that I do not know where it came from. I am…
Wang Jirao
  • 51
  • 5