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

drawImage() doesn't draw

import java.awt.*; import javax.swing.*; public class Main { JFrame jf; Main() { jf=new JFrame(); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.add(new MyCanvas()); jf.pack(); …
eXXXXXXXXXXX2
  • 1,540
  • 1
  • 18
  • 32
2
votes
4 answers

How to define a java component so that it works with a mouselistener

I have a Ball class which I want to have extend JComponent and implement mouseListener. public class Ball extends JComponent implements MouseListener { Int x, y, radius; public Ball(int X, int Y, int Radius){ //contains only three…
SoluableNonagon
  • 11,541
  • 11
  • 53
  • 98
2
votes
1 answer

Having a JComponent use up remaining width in a JPanel

I have a JLabel, a JButton, and a JTextField all arranged horizontally in that order on a JPanel. The JTextField does not initially have any text in it. The JLabel and JButton each display with their natural width. However, the width of the…
Paul Reiners
  • 8,576
  • 33
  • 117
  • 202
2
votes
1 answer

why calling repaint in this code?

if you add a jpanel instance to the content pane, the paintComponent method is called, right? content_pane.add (fDrawingPanel); so why would you call "repaint" at the first line in the run() method? (it says "to paint the loading message, but it…
Paul
  • 6,108
  • 14
  • 72
  • 128
2
votes
2 answers

Custom JComponent only Displays on JFrame not JPanel

Can somebody please help me understand why my custom JComponent 'Bar', only displays when added directly to the JFrame, and not when added to a JPanel (which is then added to the JFrame)? Thanks! package main; import java.awt.BorderLayout; import…
Reustonium
  • 2,575
  • 2
  • 16
  • 16
2
votes
1 answer

JFrame border messing up coordinates when drawing

Hi I have a small problem. I have a JFrame with a JComponent I use to display graphics. The component's preferable size is 800x600 and I create the JFrame with the JComponent like this (GC being the component): public static void main(String[] args)…
warbio
  • 466
  • 5
  • 16
2
votes
3 answers

Why can't I validate a JComponent?

From JavaDoc: public void validate() Validates this container and all of its subcomponents. Validating a container means laying out its subcomponents. That is what I want to do. With an as lightweight component as possible. But when I do this…
Jonas
  • 121,568
  • 97
  • 310
  • 388
2
votes
3 answers

What JComponents to use..?

Till now, I was using VB for developing applications. Now I have to use Java for developing the front-end. I am quite confused with the Components. Need help.. A book reference or site reference would also do the job. Basically, I will be using…
John
  • 2,820
  • 3
  • 30
  • 50
2
votes
1 answer

Reusing of components in Java not properly trimming un-reused ones

I have a javax.swing.JPanel called calcResPanel (using a java.awt.GridLayout with 1 column and indefinite (0) rows) which is to receive and display a set of BHSelectableLabels (which extend javax.swing.JTextField) with collectively represent the…
Ky -
  • 30,724
  • 51
  • 192
  • 308
2
votes
1 answer

Information about swing components (java)

After learning python (cpython) and using this page to search for tkinter widgets' options, methods and patterns, I've started to develop in jython due to javax.swing module from java which can help me make platform-independent GUIs. My question is:…
Serban Razvan
  • 4,250
  • 3
  • 21
  • 22
2
votes
2 answers

How to make my JComponent conform to JFrame.pack and Layout Managers?

I made a JComponent that displays a rectangle of a specified color. (Haven't found any other way to achieve this effect). Problem is, it doesn't follow JFrame.pack() and Layout Managers as expected. Code: import java.awt.*; import…
skytreader
  • 11,467
  • 7
  • 43
  • 61
2
votes
2 answers

Container removes component before it made visible

I am working on a big application with lots of components in it. I am trying to add a comboBox at one place and Container is removing that component before it is visible. I read some where that Java Swing validates and removes the component if it is…
arpanoid
  • 2,123
  • 4
  • 17
  • 15
2
votes
2 answers

JSlider - clicking makes the dot go towards that direction

I have a JSlider with minimum value of 0 and max value of 100. When the JSlider first launches, the value is 0. Now, when I click my mouse on the 50, or even the 20 or 100, the JSlider doesn't move to the location I click. It simply jumps a little…
CodeGuy
  • 28,427
  • 76
  • 200
  • 317
2
votes
2 answers

How to use z axis?

I have a code, which imports a brain image, I wanted to know that can how can I use the third axis, i-e z axis, (far and near axis) so that I can position the image facing upwards,(not facing user) so that outline of image is visible. import…
Riz
  • 33
  • 4
2
votes
4 answers

Is it possible to make a JComponent default to not-focusable?

I know you can call JComponent.setFocusable(false) to make a Java component not be focusable. But since I have a LOT of components in my application that I want to be that way, I was wondering if there is a simpler way than calling it on every one…
Mike O
  • 291
  • 1
  • 4
  • 17