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
-1
votes
2 answers

How to add JComponent to JPanel after JPanel has been add to JFrame

Once a JPanel has been instantiated and added to a visible JFrame, how do I add a new JComponent to it and update the display to show said new JComponent? Original Question: How to add JComponent to JPanel after JPanel has been added to a JFrame. I…
ThunderWolf
  • 130
  • 1
  • 9
-1
votes
3 answers

setBounds of JComponent to pixel width of a string

I have this inner class: private class Plats extends JComponent{ private String namn; Plats(int x, int y, String n){ namn=n; setBounds(x-10, y-10, 150, 40); setPreferredSize(new Dimension(20, 20)); …
user1339086
-2
votes
1 answer

Is it possible to use JPanel instead of JComponent on these code?

I have made this Solar System and so far I have achieved to make this code. As depicted in figure, instead of using public static class SolarCv extends JComponent I want to use public static class SolarCv extends JPanel, but it's not working.What…
-2
votes
1 answer

Adding mouse listener with JPanel to JFrame containing an Earth map (Java)

I am trying to add a mouse listener by JPanel to my JFrame. When I add the listener, the map dissapears but it is working properly (shows the Earth map) when i delete the code for the listener. The purpose of the listener is to print the…
PJacouF
  • 19
  • 8
-2
votes
1 answer

How can I add two jTextFields to JTable cell on button click

I have a JTable, edit button and save button. when I click the edit button , I want to insert two JTextFields into a particular cell which is selected . So I can write (strings) into these text fields . when I click on save button want to remove…
devilmk
  • 11
-2
votes
1 answer

Want to change a JButton with half red and half blue

I want to set my JButton background color with half red and half blue. Can I do that in java swing without using graphics 2D? Please help me!
Alonepmk
  • 13
  • 3
-2
votes
2 answers

In Jframe, why does my "getScreenSize()" only show as 19201080 and not the actual Jframe border size?

I'm quite new to this. When I manually change the Jframe border size, it still updates at "19201080" , I'm trying to get the actual Jframe width and height so I'm able to have my Circle component change size based on jframe screen size,…
Alex
  • 17
  • 4
-2
votes
2 answers

Make an object render half way through a reapint

I am currently working on an animation to compare two stock exchange algorithms. I am running the algorithms within the paint component extending JComponent. (not the best, but I don't care) I need to have the screen refresh half way through the…
-2
votes
1 answer

Moving draw on Jcomponent

I want to draw a moving cursor (in green) in my 2D plan view (in red) . I use a joystick to command it. To access to the red panel I have to get components of components from the controller following this scheme : JPanel => JScrollPane => JViewPort…
Mfaure
  • 1
  • 3
-2
votes
1 answer

Adding Multiple Instances of Classes to JFrame

I have seen a lot of questions that look like mine, and I have looked through all the answers, but I can't seem to find the answer I need. I have a Paddle class and a Ball class for a game I am making. In the Ball class, I have a paint method that…
VK17
  • 1
  • 2
-2
votes
1 answer

Adding Multiple JComponents deactivates mouse listener's

I have added 2 JComponent to JPanel.Both these JComponent have custom painted objects on them i.e multiple Circles and multiple Line2Ds.The dimensions of both these jcomponent's are set to the size of the screen which is required.When I add them to…
Raj Trivedi
  • 557
  • 7
  • 18
-2
votes
2 answers

Why does JCompnent.getBounds() always return 0 values?

When I try to get the bounds of a JPanel it always returns ( I use this.getBounds() in the constructor of the JPanel class): java.awt.Rectangle[x=0,y=0,width=0,height=0] At what point in the rendering of a Swing component does this actually get…
cj5
  • 785
  • 3
  • 12
  • 34
-2
votes
2 answers

When i convert java.util.Date to java.sql.Date i mis the time, can i do that convergance with time?

java.util.Date tempin = pLabIn.getDate(); System.out.println(tempin); java.util.Date tempout = pLabOut.getDate(); java.sql.Date labIn = new java.sql.Date(tempin.getTime()); System.out.println(labIn); java.sql.Date…
-2
votes
2 answers

Java Swing: How to specify location and size of components?

I am still learning java in college but I just would like to know the way or ways to put the JComponent's in specific location and specify their size. I have seen the methods setLocation() and that sort of methods but I just really wanna know how…
Lorenzo_g
  • 311
  • 1
  • 2
  • 8
-2
votes
1 answer

How to drag file or folder from windows explorer to java?

How to drag file or folder from windows explorer to Jpanel or text faild ... and how to calling desktop and use it? import java.awt.datatransfer.*; import java.awt.event.*; import java.awt.*; import java.io.*; import javax.swing.*; import…
1 2 3
51
52