java - JComponent not displaying on JPanel using GridBagLayout -


So after some research I am leaning towards specifying the size of my JComponent First hand, JComponent is not actually a preferred shape naturally.

Should I add a preferred size with my JComponent to my panel?

And if there is a way to fix this problem then what is the best way to do this? Ive read different people using setPreferedSize and others are saying that you should not use this method at all.

  import java.util.Scanner; Import javax.swing.JFrame; Import javax.swing.JPanel; Import javax.swing.Timer; Import java.awt.event. *; Import java.awt.GridBagLayout; Import java.awt.GridBagConstraints; Import javax.swing.JLabel; Import java.awt.Insets; Import javax.swing.JTextField; Import javax.swing.JButton; Import java.awt.Container; Import java.awt.ComponentOrientation; Public category array (static int [] array; Fixed int [] Sorted; Public static zero main (string [] args) {int size = 0; Scanner = new scanner (System.in); // Ask for the size of the array until the user does not enter a size in the correct range {System.out.print ("Enter the size of the array (should be between 10 and 100):"); Size = in.nextInt (); } While (size & lt; 10 || size> 100); Jeffre Frame = New Gefram (); Frame.setSize (1000,1000); Frame.setVisible (true); Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Array = ArrayUtil.randomIntArray (size, 200); // Create a random array of given sizes and entries 0 to 100 systems. OutprintLine (ArrayUtil.printArray (array)); // Set content pane addComponentsToPane (frame.getContentPane ()); // window display frame.pack (); Frame.setVisible (true); } Public static zero addComponentsToPane (container panel) {pane.setComponentOrientation (ComponentOrientation.LEFT_TO_RIGHT); Pane.setLayout (New GridBagLayout ()); Gridbag Consultants c = New Gridbag Consultants (); // Each component has to be added to this container: ArrayComponent array Graph = New ArrayComponent (array, incorrect); GridBagConstraints example.s.sat example variable ... c.ipady = 0; // Reset to default c.weighty = 0.0; // Request any additional vertical location c.anchor = GridBagConstraints.PAGE_END; // space under c.insets = new increments (0,0,0,0,0,0); // no padding c.gridx = 0; // starts in cell 1. c.gridwidth = 2; // 2 column wide c.gridy = 1; // line row 2 pane.add (array, c); }   

ArrayCentent Class

  import java.awt.Color; Import java.awt.Graphics; Import java.awt.Graphics2D; Import java.util.ArrayList; Import javax.swing.JComponent; ArrayComponent of Public Sector increases JComponent {// Example Variable - replace the example below with your own int [] theArray; Int hyilindex; Boolean sorted; / ** * Constructor for the object of the square array * / Public Array Component (int [] input, Boolean sorted) {// Initialize variables theArray = input; This sorted = sorted; } Public Zero Paint Component (Graphics G) {If (sorted == incorrect) {Graphics2D g2 = (Graphics2D) G; int x = 25; Int size = theArray.length; For (int i = 0; i   

Arrayuthil class

  public array ArrayUtil {Private static random generator = new random (); / ** creates an array filled with random values. @PRAM Length Length @ Linear Values ​​Number of Ranks = 0 and n - 1 * / Public Stable Int [] randomIntArray (int length, int n) {int [] Array layers filled with the length of the number between A = new int [length]; For (int i = 0; i & lt; a.length; i ++) a [i] = generator. Nxit (n); Return; } Public static string print array (int [] array) {string str = ("array = ["]; for int k = 0; (k = 0; k; array-length-1; k ++) str = Str + array [k] + "," str = str + array [k] + "]"; return str;}    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -