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
4
votes
3 answers

Get height and width of JComponent in constructor

I want to get the height and width of my JFrame so that a graphic should be at the same relative position even if the window is resized. To do this, I am trying to get the height and width in my constructor, but it always returns 0. What is the best…
trs
  • 2,454
  • 13
  • 42
  • 61
4
votes
3 answers

Check whether a JPanel contains a JButton

I have added a button to a JPanel. I want to remove the button if the JPanel contains the button. Is there any way to check whether the JPanel contains the button?
JavaLearner
  • 41
  • 1
  • 2
4
votes
5 answers

How to build click through components in Java swing?

I have built a custom component that shows only a line. The line is drawn from the top left corner to the bottom right corner as a Line2D at the paint method. The background is transparent. I extended JComponent. These line components are draggable…
tk--
  • 114
  • 2
  • 10
4
votes
2 answers

Display a row of Strings on a JComponent so that the single Strings are selectable/their location getLocation()-able?

In order to be able to display a sentence on a, say, JPanel with a GridLayout(1,0) [i.e., only one line/row] and then be able to draw a syntax tree (or similar) above it, I want to display the sentence as a row of Strings, which each include one…
s.d
  • 4,017
  • 5
  • 35
  • 65
4
votes
4 answers

Swing JComponents alignment like form

How to align these JComponents like a Form on center of the Content pane...using Swing panel1.add(l1); panel1.add(c1); panel1.add(l2); panel1.add(c2); panel1.add(b4); panel1.add(b5); …
ram
  • 41
  • 2
4
votes
2 answers

Swing : Can children exceed the bounds of their parent?

In Swing, can a child JComponent be rendered outside of the bounds of its parent JComponent, or are children always clipped to the bounds of their parent?
Tony the Pony
  • 40,327
  • 71
  • 187
  • 281
4
votes
0 answers

How do I go about implementing a tray that appears on controls?

I have a screen like so: +--------+---------------------+ |___A____| | |________| JComponent I am | |________| drawing on | |________| __ __ | |________| | | | |________| …
davidahines
  • 3,976
  • 16
  • 53
  • 87
4
votes
2 answers

Resize JProgressBar if JFrame resizes

I want to resize my JProgresbar when I resize my JFrame the size of my JProgresBar is calculated like this: progressBar.setPreferredSize(new Dimension(getWidth() - 100, 50)); but when I resize my JFrame the size of the progressbar will always stay…
vanlooverenkoen
  • 2,121
  • 26
  • 50
4
votes
1 answer

Custom component doesn't show up

When I set size of the component something more than the x and y of the location of the component both of them show up, otherwise, they don't. Here is my code: public class AdamakPogram{ public static void main(String[] args) { PlayGround…
Mohsen
  • 63
  • 8
4
votes
1 answer

Count number of Children in JPanel

I have a JPanel, to which I have added an unknown number of JComponents. How can I count the number of JComponents in that JPanel? I have looked at the API, but I see no method for retrieving the children so that I can count them. Is this possible…
Evorlor
  • 7,263
  • 17
  • 70
  • 141
4
votes
2 answers

How to determine if 2 components are on the same frame? (SWING)

I could go on and iterate over their parents using getParent() on each until i get to a shared parent or null, but this looks like a bad solution, is there a better approach? Basiclly my use case is in a FocusListener, on focusLost() i want to know…
Ofek Ron
  • 8,354
  • 13
  • 55
  • 103
4
votes
1 answer

How do I set the component background to a specific color in JGraphX?

I want to make the background of a JGraphX graph component (https://github.com/jgraph/jgraphx) a specific color all over. I tried the standard call for any Swing component: graphComponent.setBackground(Color.BLACK); but this has no effect. I tried…
user3062529
  • 87
  • 1
  • 8
4
votes
1 answer

Trouble Drawing Arcs Between Adjacent Edges of Triangle

I have been trying to write the code for generating random triangles and drawing arcs between the adjacent edges of the trianglefor describing the angle between them. It almost works. But it seems my math failed somewhere and arcs are not drawn…
pinkpanther
  • 4,770
  • 2
  • 38
  • 62
4
votes
2 answers

How to install Joomla 2.5 component by copying the files without using the J install manager

When installing custom component on a Joomla 2.5 everything works well. If I just copy and paste the content of the component in the appropriate folder /components/com_mycomponent without installing it the directory structure becomes the same but…
Dim Dov
  • 73
  • 1
  • 5
4
votes
2 answers

JComponent: how to set maximum width?

I need to make JComponent's width to be 300 or less, but height should be variable (depending on content of JComponent). Firstly, I tried to use myComponent.setMaximumSize(300, 9999); but I found that this method has absolutely no effect, and…
Dmitry Frank
  • 10,417
  • 10
  • 64
  • 114