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

Java swing JComponent "size"

I'm doing a project where i need some custom swing components. So far I have made a new button with a series of images (the Java Metal look doesn't fit with my UI at all). Ive implemented MouseListener on this new component and this is where my…
Alex
  • 650
  • 9
  • 23
3
votes
1 answer

Keymap, InputMap, ActionMap, KeyListener — choice overload

I couldn't find a concise answer about the relationships among all these, so that I can pick up best practices and get going. JTextComponent has: The old addKeyListener(..). We write a KeyListener with methods that get called on keyPressed(..),…
Evgeni Sergeev
  • 22,495
  • 17
  • 107
  • 124
3
votes
4 answers

The contents of my JComponent only refresh after a manual resize

I am trying to figure out why my JComponent refreshes when I manually drag my window, but it doesn't refresh when I call repaint or revalidate. The data is ready to be displayed, but it just won't show until I manually resize. Can anybody give some…
user372304
  • 143
  • 1
  • 8
3
votes
2 answers

Displaying a JComponent inside a JPanel on a JFrame

I am failing to display a JComponent inside a JPanel on a JFrame. The following does not work. JComponent component = ... panel.add(component, BorderLayout.CENTER); frame.add(panel, BorderLayout.CENTER); But if I add the JComponent to the…
walters
  • 1,427
  • 3
  • 17
  • 28
3
votes
1 answer

Forcing a JComponent to be square when being resized

I have a JComponent that does custom drawing, and overrides the following methods: public Dimension getPreferredSize() { return new Dimension(imageWidth, imageHeight); } public Dimension getMinimumSize() { return new Dimension(imageWidth,…
DanielGibbs
  • 9,910
  • 11
  • 76
  • 121
3
votes
1 answer

How to use “Java range slider“ in MATLAB

I have noticed that MATLAB support a few jcomponents founded in without any additional downloading, I know how to define a “Java range slider“ but i need to use to set its two values or get the two values and so on. Could any one please help me with…
Hussein
  • 653
  • 3
  • 10
  • 28
3
votes
2 answers

Resizing Image in JPanel

I am tryimg to set an image as background in JPanel and resize it to desired size. This is MyPanel where i choose image and set it as backgorund: public class MyPanel extends JPanel { Image img; public MyPanel(LayoutManager l) { …
Krzysztof Majewski
  • 2,494
  • 4
  • 27
  • 51
3
votes
1 answer

How could I allow only unique strings in a JList?

I have a JList that holds a bunch of strings . I would like it to act like a Set , so that it will only hold unique values . Is there any way to achieve this without checking that a new string doesn't already exist there ?
Geo
  • 93,257
  • 117
  • 344
  • 520
3
votes
2 answers

How to keep the highlight border of a JComponent, when custom border is set

I have a JTextField, where I've set some custom properties: nameField.setPreferredSize(new Dimension(275,40)); nameField.setBackground(bgColor); nameField.setForeground(txtColor); nameField.setFont(new…
Frederik Wordenskjold
  • 10,031
  • 6
  • 38
  • 57
3
votes
3 answers

JFrame that has multiple layers

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…
phunehehe
  • 8,618
  • 7
  • 49
  • 79
3
votes
2 answers

Swing components : vertical text question

If I have a button like the one in this image : http://www.freeimagehosting.net/image.php?4cd775814c.png how could I make the text display itself vertically ? As in j B u t t o n 1 I would like to know how to do the same thing for JLabel . I'm…
Geo
  • 93,257
  • 117
  • 344
  • 520
3
votes
1 answer

Does using setOpaque(false) impact painting performance on Swing JComponents?

My question is whether the use of setOpaque(false), which I've come to use with JPanel to layout UI in Swing, impacts painting performance more than keeping everything opaque (where isOpaque() returns true). I'm not very familiar with how Swing…
Sammy Guergachi
  • 1,986
  • 4
  • 26
  • 52
3
votes
1 answer

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…
anon235370
3
votes
1 answer

Does Component#removeAll() clean up Observer/Listeners of removed controlls?

I have a container containing JComponents like JButton or JSlider having listeners (onClick, onValueChanged...). Sometimes the containers content is removed with container.removeAll() and refilled with JComponents. The listeners of the components…
alex
  • 5,516
  • 2
  • 36
  • 60
3
votes
1 answer

No Enclosing instance error

So I'm working through a Java book and I've come to this program. However when I'm working with it in Eclipse it gives me a No Enclosing Instance of type .... error I'm pretty baffled by this as to why this error pops up. Here is my code: I've…
user3147966