Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 21st, 2006, 11:40 PM   #11
oNe8
Newbie
 
oNe8's Avatar
 
Join Date: Jan 2006
Posts: 17
Rep Power: 0 oNe8 is on a distinguished road
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.
oNe8 is offline   Reply With Quote
Old Feb 22nd, 2006, 12:14 AM   #12
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 837
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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.
titaniumdecoy is offline   Reply With Quote
Old Feb 22nd, 2006, 7:11 AM   #13
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
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!
ReggaetonKing is offline   Reply With Quote
Old Feb 22nd, 2006, 4:26 PM   #14
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
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
Kilo is offline   Reply With Quote
Old Feb 22nd, 2006, 7:44 PM   #15
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
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
Kilo is offline   Reply With Quote
Old Feb 22nd, 2006, 8:00 PM   #16
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 837
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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.
titaniumdecoy is offline   Reply With Quote
Old Feb 22nd, 2006, 8:53 PM   #17
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
[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!
ReggaetonKing is offline   Reply With Quote
Old Feb 22nd, 2006, 9:01 PM   #18
oNe8
Newbie
 
oNe8's Avatar
 
Join Date: Jan 2006
Posts: 17
Rep Power: 0 oNe8 is on a distinguished road
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.
oNe8 is offline   Reply With Quote
Old Feb 23rd, 2006, 2:23 PM   #19
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 837
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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();
    }
}
titaniumdecoy is offline   Reply With Quote
Old Feb 23rd, 2006, 3:20 PM   #20
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
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
Kilo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:09 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC