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
1 answer

jScrollPane can't add component

I have a jScrollPane and a button on a form. The button adds a component to the jScrollPane. I'm using a FlowLayout with a center alignment to arrange the components within the jScrollPane. The first component has no problems appearing and is…
Feanaro
  • 922
  • 3
  • 19
  • 35
4
votes
3 answers

How to center text and a JComponent in a JTextPane vertically?

Currently it looks so What to do so that it looks so? Below is my code: JFrame f = new JFrame(); JTextPane textPane = new JTextPane(); JTextField component = new JTextField(" "); …
ka3ak
  • 2,435
  • 2
  • 30
  • 57
4
votes
2 answers

Change cursor for all buttons on Swing app

I have a Swing app with a main frame and some other forms loaded inside it. I Need to implement a general method to set the hand cursor for all buttons on any form. This is similar of what we do with css on web pages (input[type=button] {…
Juan Jimenez
  • 5,812
  • 6
  • 28
  • 37
3
votes
2 answers

2D grid of JComponents (Swing)

I'm trying to make a 2D grid of JTextFields to represent a level map. I've come to the following for initializing the 2D Array of TextFields: fields = new TextField[level.rows][level.columns]; TextField field; for (int r = 0; r < level.rows;…
user717572
  • 3,626
  • 7
  • 35
  • 60
3
votes
4 answers

Drawing a rectangle with a button

I am a beginner, starting a simple project on GUI. The RectangleComponent should draw a Rectangle on the form with a button click. A rectangle won't draw with the following code, but if I put the same 2 lines of code outside the listener, it…
Homo homilis
  • 59
  • 1
  • 7
3
votes
3 answers

What's a convenient way to set default settings for all JComponents

I want a way to set default settings like, background colour, size etc. for all components I use in my GUI, what's a convenient way to do this? so when I do new JButton or JLabel etc. it will already have the settings applied?
fenerlitk
  • 5,414
  • 9
  • 29
  • 39
3
votes
2 answers

Graphics2D and JComponent

I have not used Swing/G2D much, so please be patient. I have the following class which is a component on my GUI (meant to be a kind of Canvas to draw on): import javax.swing.*; import java.awt.*; public class DrawPanel extends JComponent{ public…
Jack H
  • 2,440
  • 4
  • 40
  • 63
3
votes
2 answers

Java Font problem

Say I have a Swing JComponent and I set a Font for the text of that JComponent. I build the project and create a .jar file of my project. Now, If I run this jar file from another computer where the Font is not install, what will be happen? Will the…
Dewsworld
  • 13,367
  • 23
  • 68
  • 104
3
votes
1 answer

how to call compoment from another frame

hi i have two frames created in the same way: public class DateFilter extends JFrame { private final JDateChooser dateChooser = new JDateChooser(); private final JDateChooser dateChooser_1 = new JDateChooser(); private final JComboBox comboBox =…
Edgar Buchvalov
  • 257
  • 2
  • 12
  • 22
3
votes
2 answers

setting components' locale is unsuccessful

I need my application to set programmatically a locale of all the sensitive components, like JTextFields and JTextAreas. Also I have date information (month written as a word) which is locale-sensitive too. I wrote the following code, but it…
ilja
  • 95
  • 8
3
votes
2 answers

Get all swing components in a container

I think we can use jScrollPane.getComponents() to get awt components of a jscrollpane. My question is: is there a way to get swing components of a container some how?
Bee
  • 12,251
  • 11
  • 46
  • 73
3
votes
6 answers

What's the rule of thumb regarding Swing component extension?

When dedicating a class to a particular Swing component, is it better to extend that particular component, or construct it internally and provide a reference? public class Foo extends JComponent{ } OR public class Foo{ public JComponent…
mre
  • 43,520
  • 33
  • 120
  • 170
3
votes
1 answer

a java JComponent that can render a Font character in pixels

I am wondering if such a java component even exists, please allow me to elaborate. The component is supposed to be a grid-like component, derived from JComponent. The main face is a grid, and it will be used to render a font character. The grid is…
J.E.Y
  • 1,173
  • 2
  • 15
  • 37
3
votes
2 answers

Java - An easy way to request focus on click without a mouse listener?

Is there a easier way for a JComponent to request focus when you click on it than having to set up a MouseListener?
Jeremy
  • 98
  • 7
3
votes
1 answer

Correctly finding frame rate on a custom Java Component

I am not confident my framerate code is correct, and I have not been able to find exact examples of what I am looking for. Essentially I have subclassed java.awt.Component, and inside the paint(Graphics) method I call my calculateFrameRate()…
Hamy
  • 20,662
  • 15
  • 74
  • 102