"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!
Don't use a null layout. Learn to use LayoutManagers.
Don't use a null layout. Learn to use LayoutManagers: download.oracle.com/javase/tutorial/uisw... LayoutManagers allow you to properly handle things window resizing or dynamic component counts. They might seem intimidating at first, but they are worth the effort to learn.
Nested Layout Example The Java Tutorial has comprehensive information on using layout managers. See the Laying Out Components Within a Container lesson for further details. One aspect of layouts that is not covered well by the tutorial is that of nested layouts, putting one layout inside another to get complex effects.
The following code puts a variety of components into a JFrame to demonstrate how to use nested layouts. All the layouts that are explicitly set are shown as a TitledBorder for the JPanel on which they are used. Notable aspects of the code are: There is a JComboBox to change PLAF at run-time.
The GUI is expandable to the user's need. The image in the bottom of the JSplitPane is centered in it's container. The JLabel instances on the left are dynamically added using the JButton.
NestedLayoutExample. Java import java.awt. *; import java.awt.image.
BufferedImage; import java.awt.event. ActionListener; import java.awt.event. ActionEvent; import javax.swing.
*; import javax.swing.table. DefaultTableModel; import javax.swing.border. TitledBorder; /** A short example of a nested layout that can change PLAF at runtime.
The TitledBorder of each JPanel shows the layouts explicitly set. @author Andrew Thompson @version 2011-04-12 */ class NestedLayoutExample { public static void main(String args) { Runnable r = new Runnable() { public void run() { final JFrame frame = new JFrame("Nested Layout Example"); frame. SetDefaultCloseOperation(JFrame.
EXIT_ON_CLOSE); final JPanel gui = new JPanel(new BorderLayout(5,5)); gui. SetBorder( new TitledBorder("BorderLayout(5,5)") ); //JToolBar tb = new JToolBar(); JPanel plafComponents = new JPanel( new FlowLayout(FlowLayout. RIGHT, 3,3)); plafComponents.
SetBorder( new TitledBorder("FlowLayout(FlowLayout. RIGHT, 3,3)") ); final UIManager. LookAndFeelInfo plafInfos = UIManager.
GetInstalledLookAndFeels(); String plafNames = new StringplafInfos. Length; for (int ii=0; iiAdd(plafChooser); final JCheckBox pack = new JCheckBox("Pack on PLAF change", true); plafComponents. Add(pack); plafChooser.
AddActionListener( new ActionListener(){ public void actionPerformed(ActionEvent ae) { int index = plafChooser. GetSelectedIndex(); try { UIManager. SetLookAndFeel( plafInfosindex.getClassName() ); SwingUtilities.
UpdateComponentTreeUI(frame); if (pack.isSelected()) { frame.pack(); frame. SetMinimumSize(frame.getSize()); } } catch(Exception e) { e.printStackTrace(); } } } ); gui. Add(plafComponents, BorderLayout.
NORTH); JPanel dynamicLabels = new JPanel(new BorderLayout(4,4)); dynamicLabels. SetBorder( new TitledBorder("BorderLayout(4,4)") ); gui. Add(dynamicLabels, BorderLayout.
WEST); final JPanel labels = new JPanel(new GridLayout(0,2,3,3)); labels. SetBorder( new TitledBorder("GridLayout(0,2,3,3)") ); JButton addNew = new JButton("Add Another Label"); dynamicLabels. Add( addNew, BorderLayout.
NORTH ); addNew. AddActionListener( new ActionListener(){ private int labelCount = 0; public void actionPerformed(ActionEvent ae) { labels. Add( new JLabel("Label " + ++labelCount) ); frame.validate(); } } ); dynamicLabels.
Add( new JScrollPane(labels), BorderLayout. CENTER ); String header = {"Name", "Value"}; String a = new String0; String names = System.getProperties(). StringPropertyNames().
ToArray(a); String data = new Stringnames. Length2; for (int ii=0; iiSetAutoCreateRowSorter(true); } catch(Exception continuewithNoSort) { } JScrollPane tableScroll = new JScrollPane(table); Dimension tablePreferred = tableScroll. GetPreferredSize(); tableScroll.
SetPreferredSize( new Dimension(tablePreferred. Width, tablePreferred. Height/3) ); JPanel imagePanel = new JPanel(new GridBagLayout()); imagePanel.
SetBorder( new TitledBorder("GridBagLayout()") ); BufferedImage bi = new BufferedImage( 200,200,BufferedImage. TYPE_INT_ARGB); Graphics2D g = bi.createGraphics(); GradientPaint gp = new GradientPaint( 20f,20f,Color. Red, 180f,180f,Color.
Yellow); g. SetPaint(gp); g. FillRect(0,0,200,200); ImageIcon ii = new ImageIcon(bi); JLabel imageLabel = new JLabel(ii); imagePanel.
Add( imageLabel, null ); JSplitPane splitPane = new JSplitPane( JSplitPane. VERTICAL_SPLIT, tableScroll, new JScrollPane(imagePanel)); gui. Add( splitPane, BorderLayout.
CENTER ); frame. SetContentPane(gui); frame.pack(); frame. SetLocationRelativeTo(null); try { // 1.6+ frame.
SetLocationByPlatform(true); frame. SetMinimumSize(frame.getSize()); } catch(Throwable ignoreAndContinue) { } frame. SetVisible(true); } }; SwingUtilities.
InvokeLater(r); } } Screen Shots Nimbus PLAF Windows PLAF Mac OS X Aqua PLAF.
Andrew Thompson +1 for your ..., Edit: but is there some real reason(s) for calling twice "frame. SetMinimumSize(frame.getSize());" into code block "Change Plaf" – mKorbel May 2 at 7:18 The real reason is that I really made a mistake. ;) Code edited.
– Andrew Thompson May 2 at 8:03.
If you are using null layout manager you always need to set the bounds of a component. That is the problem in your case. You should do what everyone suggest here and go and use some layout manager believe they save time.
Go and check out the tutorial in @jzd's post. Enjoy, Boro.
As I can remember, the null layout means an absolute position so it will be pretty hard you to count the X point for your JTable left upper corner location. But if you just want to have all panel components one by one you can use FlowLayout() manager as JPanel panel=new JPanel(new FlowLayout()); panel. Add(new aComponent()); panel.
Add(new bComponent()); panel. Add(new JTable()); or if you need to fill the panel you should use GridLayout() as... int x=2,y=2; JPanel panel=new JPanel(new GridLayout(y,x)); panel. Add(new aComponent()); panel.
Add(new bComponent()); panel. Add(new JTable()); Good luck.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.