Not sure how you can fix your border problem but to fix your layout situation I would just use springlayout. Springlayout is just a way to better layout your elements within the JPanel. You can find out more about it Java Sun Tutorial Specifically you use it by setting where you want your North, South, West and East borders of each element.To do this you would have to first take your label calls out of the add so each one can be named.
So instead of: add(new JLabel("Text field:")) Do: JLabel myLabelName = new JLabel("Text field:"); add(myLabelName) For each of your elements (JLabels, JTextAreas and JTextField). Once this is done you can easily set the layout Springlayout layout = new SpringLayout(); setLayout(layout) Then for each of the elements you have to set any of the borders you want. They have to be in the specific order South, the North, West then East.
Though you don't have to use all four borders if you don't want to. Here is an example on how to set your first text area, the one on the top layout. PutConstraint(SpringLayout.
NORTH, FirstTextAreaName, 10, SpringLayout. NORTH, this); layout. PutConstraint(SpringLayout.
WEST, FirstTextAreaName, this.getWidth()/2, SpringLayout. WEST, this); layout. PutConstraint(SpringLayout.
EAST, FirstTextAreaName, -10, SpringLayout. EAST, this) This example doesn't set the south of the text area but if you did want to it would have to be first. The first line sets the north side of the text area to be 10 pixels away from the top.
When setting the other areas you but the previous (above) areas name instead of this and say it is 10 pixels away from the south of the previous one: layout. PutConstraint(SpringLayout. NORTH, SecondTextAreaName, 10, SpringLayout.
SOUTH, FirstTextAreaName) The second line in the above example sets the east side of the text area to start halfway through your main panel. The last, third, line sets the east side of the text area to be 10 pixels from the east side of your main panel.
Not sure how you can fix your border problem but to fix your layout situation I would just use springlayout. Springlayout is just a way to better layout your elements within the JPanel. You can find out more about it Java Sun Tutorial Specifically you use it by setting where you want your North, South, West and East borders of each element.To do this you would have to first take your label calls out of the add so each one can be named.
So instead of: add(new JLabel("Text field:")); Do: JLabel myLabelName = new JLabel("Text field:"); add(myLabelName); For each of your elements (JLabels, JTextAreas and JTextField). Once this is done you can easily set the layout. Springlayout layout = new SpringLayout(); setLayout(layout); Then for each of the elements you have to set any of the borders you want.
They have to be in the specific order South, the North, West then East. Though you don't have to use all four borders if you don't want to. Here is an example on how to set your first text area, the one on the top.
Layout. PutConstraint(SpringLayout. NORTH, FirstTextAreaName, 10, SpringLayout.
NORTH, this); layout. PutConstraint(SpringLayout. WEST, FirstTextAreaName, this.getWidth()/2, SpringLayout.
WEST, this); layout. PutConstraint(SpringLayout. EAST, FirstTextAreaName, -10, SpringLayout.
EAST, this); This example doesn't set the south of the text area but if you did want to it would have to be first. The first line sets the north side of the text area to be 10 pixels away from the top. When setting the other areas you but the previous (above) areas name instead of this and say it is 10 pixels away from the south of the previous one: layout.
PutConstraint(SpringLayout. NORTH, SecondTextAreaName, 10, SpringLayout. SOUTH, FirstTextAreaName); The second line in the above example sets the east side of the text area to start halfway through your main panel.
The last, third, line sets the east side of the text area to be 10 pixels from the east side of your main panel.
For the layout problem, try a columnConstraints value of rightfill instead of rightleft. For the other issue, this appears to be a look-and-feel inconsistency. I ran your code in Windows, and the differences are there too, but less flagrant.My suggestion would be to set identifical borders explicitly for text fields and text areas.
SetLayout(new MigLayout( "wrap 2", "rightfill" )); JTextField textField; JScrollPane scrollPane; add(new JLabel("Text field:")); textField = new JTextField(NUM_CHARACTERS_WIDTH); textField. SetBorder( new EtchedBorder( EtchedBorder. LOWERED ) ); add(textField); add(new JLabel("No scrollpane text area:")); add(new JTextArea(NUM_ROWS, NUM_CHARACTERS_WIDTH)); add(new JLabel("Scrollpane text area:")); scrollPane = new JScrollPane(new JTextArea(NUM_ROWS, NUM_CHARACTERS_WIDTH)); scrollPane.
SetBorder( new EtchedBorder( EtchedBorder. LOWERED ) ); add(scrollPane); add(new JLabel("Text field:")); textField = new JTextField(NUM_CHARACTERS_WIDTH); textField. SetBorder( new EtchedBorder( EtchedBorder.
LOWERED ) ); add(textField); If you can't get MigLayout to align your components, considering using java.awt. GridBagLayout: import static java.awt. GridBagConstraints.
*; setLayout( new GridBagLayout() ); GridBagConstraints leftCons = new GridBagConstraints(); leftCons. Anchor = NORTHEAST; leftCons. Fill = NONE; leftCons.
Weightx = 1.0; leftCons. Gridy = RELATIVE; leftCons. Gridx = 0; leftCons.
Insets = new Insets( 4, 8, 4, 8 ); GridBagConstraints rightCons = new GridBagConstraints(); rightCons. Anchor = NORTHWEST; rightCons. Fill = HORIZONTAL; rightCons.
Weightx = 1.0; rightCons. Gridy = RELATIVE; rightCons. Gridx = 1; rightCons.
Insets = leftCons. Insets; add(new JLabel("Text field:"), leftCons); add(new JTextField(NUM_CHARACTERS_WIDTH), rightCons); add(new JLabel("No scrollpane text area:"), leftCons); add(new JTextArea(NUM_ROWS, NUM_CHARACTERS_WIDTH), rightCons); add(new JLabel("Scrollpane text area:"), leftCons); add(new JScrollPane(new JTextArea(NUM_ROWS, NUM_CHARACTERS_WIDTH)), rightCons); add(new JLabel("Text field:"), leftCons); add(new JTextField(NUM_CHARACTERS_WIDTH), rightCons).
The fill helps. However, the size still isn't perfect on Mac OSX: grab. By/3O9U – I82Much Apr 16 '10 at 18:57 1 Perhaps a more adaptable alternative is to adopt the preferred border of one component type and apply it to the other; e.g. , textField.
SetBorder(scrollPane.getBorder()). – Noel Ang Apr 16 '10 at 18:57 Consider giving java.awt. GridBagLayout a try.
See my amended answer for more code. – Noel Ang Apr 16 '10 at 19:16.
I know that MiGLAyout (which I love, BTW) has the ability to do special handling for visual alignment vs strict pixel alignment. You may be running into this... The 'al' unit identifier is used for this, but I haven't had to use it so can't provide examples. It would probably be worth downloading the MiG sample project and see if they have the same alignment issue (I'm sure they have panels similar to yours).
For what it's worth, we mix text fields and areas in the same panel quite frequently and don't run into this... We do have to set the border of the scroll pane to be the same as the border of the text field as suggested by Noel Ang. Also, instead of specifying constraints in the layout constructor, we generally specify them as we add each component - not sure if that makes a difference or not...
First off +1 for screen shots. Since you are using Mac, did you try Quaqua Look And Feel? It renders the textboxes/areas properly.
The answer is that MiG Layout folks are working on a fix for their next version. Apple has a nasty habbit of compensating by default and not let the developer decide. This is such a case where they have added a border to make it more visually like OS X.
This should be the choice of the layout manager... MigLayout can compensate for visual bounds like this but it is only done for JTabbedPane in Windows XP. I'm not sure it can be done 100% good in OS X though. I'll have to check.
We don't want the text field to just grow into the bounds. I have added this to the todo list for the next version.
For each of your elements (JLabels, JTextAreas and JTextField). Once this is done you can easily set the layout. Then for each of the elements you have to set any of the borders you want.
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.