![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Newbie
Join Date: Jan 2006
Posts: 17
Rep Power: 0
![]() |
getContentPane comes from the JFrame class, so your project will ne to extend JFrame, all the content pane really is a the a master JPanel.
usally you create a container object of the content pane rather then directly adding objects to it.
__________________
http://img523.imageshack.us/img523/8436/user9kz.jpg |
|
|
|
|
|
#12 |
|
Expert Programmer
|
In the code you posted, you could add the elements directly to the window (JFrame) by calling app.getContentPane().add(element), or alternatively add them to the panel (JPanel) by calling pan.add(element). If you choose the former you can remove pan from your code.
|
|
|
|
|
|
#13 |
|
Sexy Programmer
|
when you have BorderLayout, you have to set the button as you want by adding another agrument to the parameters of the components!
[PHP] Panel panel = new Panel(); panel.setLayout(new BorderLayout()); panel.add(new Button("Okay"), BorderLayout.SOUTH); [/PHP] Do you see what I mean? [PHP] panel.add(new Button("North"), BorderLayout.NORTH); panel.add(new Button("South"), BorderLayout.SOUTH); panel.add(new Button("East"), BorderLayout.EAST); panel.add(new Button("West"), BorderLayout.WEST); panel.add(new Button("Center"), BorderLayout.CENTER); [/PHP]
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#14 |
|
Expert Programmer
|
yes reggeaton i completely understand that concept... that is not my issue... i do not want a HUGE JTextField.. i want to be able to make it the same size as the button next to it which is also HUGE at the moment.
[php] import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.JTextField; import javax.swing.JPanel; import java.awt.BorderLayout; public class lettercount extends JFrame { public static void main(String args[]) { JPanel pan=new JPanel(new BorderLayout()); JFrame app=new JFrame("Letter Counter"); JButton fileButton=new JButton("Scan File"); JTextField filePath=new JTextField(); char[] letterArray=new char[26]; int[] letterCount=new int[26]; int count=0; for(int i=97;i<=122;i++) { letterArray[count]=(char)i; System.out.printf("%d = %s\n",count,letterArray[count]); count++; } //pan.add(BorderLayout.CENTER, filePath); //pan.add(BorderLayout.EAST, fileButton); //getContentPane().setLayout(null); //getContentPane().add(fileButton); fileButton.setBounds(24,500,72,36); // x, y, width, height fileButton.setVisible(true); pan.add(fileButton); app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); app.add(pan); app.setSize(450,250); app.setVisible(true); } } [/php] code compiles with no errors but does not complete the needed objective... it seems as if these lines below almost do nothing at all! [php] fileButton.setBounds(24,500,72,36); // x, y, width, height fileButton.setVisible(true); [/php]
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#15 |
|
Expert Programmer
|
no help for me????
![]()
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#16 |
|
Expert Programmer
|
Since you have decided to add the button to the JPanel pan, you need to change this line of code:
JPanel pan=new JPanel(new BorderLayout()); to: JPanel pan = new JPanel(); pan.setLayout(null); The layout of the container you are adding an element to that you want to position by setBounds(...) must be null. |
|
|
|
|
|
#17 |
|
Sexy Programmer
|
[PHP]
import java.awt.*; Container panel = getContentPane(); panel.setLayout(new FlowLayout()); [/PHP] what this layout does is it add the components to the "panel" and arrange em in the order that they are added! Try it out!
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#18 |
|
Newbie
Join Date: Jan 2006
Posts: 17
Rep Power: 0
![]() |
Or what you can do is use gridLayout that is only a 1x2 grid and when it adds the compents to it, it will make them the same size. Because they will be divded up to share the space.
__________________
http://img523.imageshack.us/img523/8436/user9kz.jpg |
|
|
|
|
|
#19 |
|
Expert Programmer
|
Kilo... you are extending JFrame for no reason, since you are creating a new JFrame separately. Here is an example of how to make use of extending JFrame (I included only the GUI parts of your code):
import javax.swing.*;
public class LetterCount extends JFrame
{
public LetterCount() {
// If a new LetterCount() is created without a String
// as an argument, we will call the constructor that
// takes a String argument with an empty string.
this("");
}
public LetterCount(String title) {
// Call the JFrame constructor (this class extends JFrame)
super(title);
// Create fileButton
JButton fileButton = new JButton("Scan File");
fileButton.setBounds(20,20,72,20); // x, y, width, height
fileButton.setVisible(true);
// Create filePath
JTextField filePath = new JTextField();
filePath.setBounds(120,20,200,20); // x, y, width, height
filePath.setVisible(true);
// Add fileButton and filePath to this window's default
// content pane; getContentPane() is inherited from JFrame,
// which this class extends
getContentPane().setLayout(null);
getContentPane().add(fileButton);
getContentPane().add(filePath);
// Set window attributes
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(450,250);
setVisible(true);
}
public static void main(String args[])
{
// Create a new LetterCount object; since LetterCount
// extends JFrame this will create a new window
new LetterCount();
}
} |
|
|
|
|
|
#20 |
|
Expert Programmer
|
thank you very very much man... im at work but i will attempt this within the next couple hours
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|