java - What's the best rule for fitting a dynamic JTable inside a dialog or a frame?(height issue) -


I want to calculate the height of a dialog which contains only one table depending on how many rows the table is , Using the cross multiplied rule. For example, I initially check that for some value my table dialogue (without the bottom space) is appropriate and after that I use cross multiplication rule because the data is dynamic. But unfortunately this rule does not solve the problem. What is the best rule to fit a dynamic table inside a dialog or frame? Here is my code

  public square flowout changing {public static zero main (string [] arg) {// just for testing, but the data is being from database and it is a dynamic object [ ["]", ["Cathy", "Smith", "Snowboarding", New Integer (5)}, {"John", "Do", "Rowing", New Integer (3)}, {"Sue", " New "Integre", "Joe", "Brown", "Pool", New Integer ("Black", "Knitting", New Integer (2)}, {"Jane", "White", "Speed ​​Readings", New Integer (20)} 10)}} ; Object [] columnname = {"first name", "last name", "age"}; Last JTable table = new JTable (data, column name); JFrame aWindow = New JFrame ("This is a test"); AWindow.setBounds (50, 50, 500, 500); aWindow.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Flow layout flow = new flow layout (flow layout. LEFT, 20, 30); Container material = aWindow.getContentPane (); content.setLayout (flow); Jebton Jebton = New Jebton ("Press Me"); Action Listener L = New Expertist () {Public Zero Action Perfarm (Action Avent E) {JPNL JPN = NewNPNL (); JPanel.setLayout (new gridout (outbound); Gridbag Consultants GBC = New Gridbag Consultants (); Gbc.anchor = GridBagConstraints.NORTHWEST; Gbc.fill = GridBagConstraints.BOTH; Gbc.gridx = 0; Gbc.gridy = 0; Gbc.weightx = 1.0; Gbc.weighty = 1.0; jPanel.add (table, gbc); JDialog Zediolog = New JDILOG (); Jdialog.setContentPane (JPanel); Jdialog.setLocationRelativeTo (zero); Int height = table.getModel (). GetRowCount () * 25; Jdialog.setSize (400, height); Jdialog.setVisible (true); }}; JButton.addActionListener (L); content.add (jButton); AWindow.setVisible (true); }}    

Scroll-panel here.

Enter image details here

  import Java.awt *. Import java.awt.event. *; Import javax.swing. *; Import javax.swing.border.EmptyBorder; Classroom FlowoutPangingGap {Public Stable FINAL END ROWS = 3; FlowLayoutChangingGap () {// to test the bus, but the data is getting from the database and this is the dynamic object [] [] data = {{"Cathy", "Smith", "Snowboarding", New Integer (5 } "New" (")", "New", "New", "New", "New", " The object [] columnname = {"first name", "jane", "white", "speed readings", new integer (20)}, {"joe", "brown", "pool", new integer (10)}} , "Last name", "age"}; final JTable table = new JTable (date {Override public dimension} GetPreferredScrollableViewportSize () {dimension d = getPreferredSize (); // Note: The margin line is included in the intite int n = getRowHeight (); // + getRowMargin (); // tbd: insets ? We are one-stop, return new dimensions (D. Wide, (n * ROWS));}} JP Penal = new zpn (); JPanel.setBorder (new blank border (6, 6, 6, 6) ); JPanel.setLayout (new gridlate ()); JScrollPane sp = new JScrollPane (table); //sp.getViewport (); jPanel.add (SP); JDialog Zediolog = New JDILOG (); jdialog.setDefaultCloseOperation (JFrame. DISPOSE_ON_CLOSE); Jdialog.setContentPane (JPanel); Jdialog.setLocationRelativeTo (zero); jdialog.pack (); Jdialog.setVisible (true); } Public Stable Zero Main (string [] Args) {Runnabal R = New Runnabal () {@ Override Public Wide Run (New Flow Layout Changing Gap); }}; // swing GUI should be made on ADT // http://docs.oracle.com/javase/tutorial/uiswing/concurrency and SwingUtilities.invokeLater (r); }}    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -