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

Try - Except in Python for given amount of time

I am using Marathon (Java desktop application testing tool) to automate regression testing. Marathon uses Jython so I can use Java libraries and Python libraries. As my script goes through filling out certain fields, various fields appear (or don't…
Nick L
  • 281
  • 1
  • 6
  • 18
5
votes
2 answers

Size of Text Area in java

I am writing a code for basic GUI. There i need a Text Area. But i can not make the Text Area in my desirable size. i use setPreferredSize method to set the dimension of the Text Area. But it did not work. I also tried setSize method but did not…
seal
  • 1,122
  • 5
  • 19
  • 37
5
votes
2 answers

Get a component from a JTextPane through javax.swing.text.Element?

I am using a JTextPane to display characters and symbols, where the latter are represented by custom painted JComponents. For example, the text pane might show something like this: The text pane is user editable and it is allowed for the user to…
AplusKminus
  • 1,542
  • 1
  • 19
  • 32
5
votes
4 answers

Java Swing Components does not have correct Size when added to JPanel

It's my first Post here, so forgive me please if i'm doing something wrong. My Problem is: I am trying to add Components to a JPanel with defined values for Size etc. But when i add them to the Panel, they do absolutely not have the Size and…
Furious Gamer
  • 359
  • 1
  • 3
  • 16
5
votes
4 answers

getting right click location from popmenu action event

I have a java program that opens a popup menu when right clicked in a JPanel. When any of the popup menu items are clicked, I want to print the location of the right click that triggered the popupmenu in the terminal. How do I do this? How do I get…
user1868856
  • 113
  • 2
  • 5
5
votes
1 answer

How to get COMPONENT (not data) at Index n from JList

I create a JList by passing it an array of data public class MyJList extends JList() { ... public MyJList(final Object[] listData) { super[listData]; } I render this list using the ListCellRenderer, which provides me a Component for…
Steve Cohen
  • 4,679
  • 9
  • 51
  • 89
5
votes
1 answer

How to wrap text around components in a JTextPane?

I don't understand the wrapping behavior in a JTextPane. If I insert a short text, then a JComponent and then again the short text I can see the inserted stuff in one line if the frame is large enough of course. But if the text is much longer so…
ka3ak
  • 2,435
  • 2
  • 30
  • 57
5
votes
4 answers

How do I get the image paint/paintComponent generates?

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…
user20298
  • 1,795
  • 3
  • 16
  • 10
4
votes
3 answers

Ball Animation in Swing

The Problem is when I resize the JFrame the animation goes on with it's Pre supplied dimensions for JComponent . Is there a way that I can update my width and height variables as I resize the JFrame, so that the Animation can run along with the new…
nIcE cOw
  • 24,468
  • 7
  • 50
  • 143
4
votes
1 answer

Java Swing: Changing color of a ball on mouseEntered

I can already create a ball in a panel on MousePressed and MouseReleased and update coordinates with MotionListener and change the color of the ball when the mouse is over it. This works fine in the myPanel class because the panel has defined…
SoluableNonagon
  • 11,541
  • 11
  • 53
  • 98
4
votes
4 answers

Best way to display Components in a JTable?

I'm not asking HOW to display a Component in a JTable, as there are several tutorials and examples online. However, I want to know what the BEST way of going about this might be. For instance, most tutorials I run into have examples that create…
Ky -
  • 30,724
  • 51
  • 192
  • 308
4
votes
4 answers

Java. Swing. JComponent's clickable area

I have a custom component displaying *.png image. The image has transparent and non-transparent area. If I add ActionListener(or MouseClickListener) to component, it will raise events even if I click on transparent area of component. Visually it…
Yegoshin Maxim
  • 872
  • 2
  • 21
  • 54
4
votes
2 answers

Java - Remove component (Files of Type) from JFileChooser

How can I remove component (Files of Type) from JFileChooser; both label and its combobox? I have the following code: JFileChooser fileChooser = new…
jadrijan
  • 1,438
  • 4
  • 31
  • 48
4
votes
1 answer

How to listen to child components?

I have a JPanel with a grid of JLabels added. I'd like a MouseListener to listen for MouseEvents, but the JLabels seem to be in the way and no MouseEvent fires when clicking in the location where a JLabel is located. Is there a relient way to listen…
Lucas
  • 1,149
  • 1
  • 9
  • 23
4
votes
1 answer

Interchangeable JComponent skins for JButton

I'm attempting to create a custom JButton that has interchangeable skin components. Using CardLayout as the switching mechanism, I'm having difficulty with the JComponent (i.e. skin component) laying flush across the JButton. For instance, import…
mre
  • 43,520
  • 33
  • 120
  • 170
1 2
3
51 52