I cannot 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 a JComponent to the JFrame [for example frame.add(component, BorderLayout.CENTER);], it will display the content.
frame.add(component, BorderLayout.CENTER);
Any ideas
A JPaneldefault layout is FlowLayout, so you do not need to specify the center of the panel.
JPanel
FlowLayout
Just do:
panel.add(component);
Alternatively, follow these steps:
panel.setLayout(new BorderLayout()); panel.add(component, BorderLayout.CENTER);
By default, JComponent is not the preferred size.
JPanel FlowLayout. , , 0, .
, JFrame, BorderLayout. , , , , ,
, , .
Source: https://habr.com/ru/post/1761533/More articles:Как выбрать node без атрибутов с помощью xpath? - xmlКак использовать Netbeans IDE 6.9 для разработки Scala -Lift? (то есть: настройка, начальные настройки, рабочие процессы и т.д.) - scalaJQuery: выберите дочерний div в своем индексе внутри родительского div - jqueryCamera Selection - c ++How to implement Tenant View Filter security template in a common database using ASP.NET MVC2 and MS SQL Server - securityIt is not possible to pass a hash and a string of functions together in perl! - perlThe minimum required to use step-by-step debugging on a machine without development - debuggingWhat does this Perl code do? - includePython unix timestamp conversion and timezone - pythonCSS - Оптимизация закругленных углов для скорости - performanceAll Articles