Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JComponent Subclass  RSS feed

 
Rafael Afonso
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello:
I have this class:

Now the Test Class:

Now, the strnge thing: When I run Test Class, the JFrame does not show my component. I try use setVisible(true) instuction in last line constructor component, but it does not work. Only when I did my component extends JPanel and not JComponent, it works.
My question: there is not any way to show my component as JComponent derivated? Only if is it a JPanel Subclass?
Thanks,
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you setting a layout on the JTextSlider in that "// I build internal components" part?

JPanel has a default FlowLayout, while JComponent just has null for layout. With no layout, your components have no idea where to put themselves, how big they are, etc. without explicit setBounds() calls.

Just set a layout in the constructor and all your problems are solved!
 
Rafael Afonso
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works, thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!