Java Swing does not paint the subsidiary components



  • The question is for veterans to work with the Java Swing library, or for those who understand her work well.

    The following are identical objects created by one class. In the first pillar, everything is well painted, as in others. However, when I want to add all these objects to one screen, Swing ignores the subsidiary elements of all components after the first. Diagnostics showed that the subsidiaries were in the components, but no paintComponent(s) was detected. Each component has a castle Layout, all the subsidiaries with their sketches.

    Could it be too long to these methods?

    UPD: Measuring the time of the caste methods: The drawing of the text is performed for an average of 23.6 mx (due to the use of FontMetrics.getStringBounds()), the CustomLayout.layoutComponent averages 43.3 mx

    UPD2: Reduced Layout to 10 max, replaced the hard text components on JLabel, the problem remained.

    введите сюда описание изображения



  • Problem solved!

    I want to share experiences with those who have never created their LayoutManager.

    In my case, I put the entries on the components with the reference point matching the reference point for the parent element. However, this was a mistake, as the components need to be positioned directly within the element with a reference point matching the position of the parent component.

    I mean, instead.

    component.setBounds(parentBounds.x + offsetX, parentBounds.y + offsetY, width, height);
    

    Use

    component.setBounds(offsetX, offsetY, width, height);
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2