ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
below is my code
I'm using gridbaglayout.
the layout has created extra space from the outside borders of the gui.
Does anyone know in what direction i should study to eliminate this?
I'm also having problems on my file processing.
if there are any pointers, i would be very grateful.
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.io.*;
public class homeworkJava extends JFrame
{
Container container= getContentPane();
GridBagLayout layout= new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
Box box1 = Box.createVerticalBox();
Box box2 = Box.createVerticalBox();
Box box3 = Box.createVerticalBox();
JTextField commands = new JTextField(18);
JLabel GeneraLabel = new JLabel("Genera", JLabel.RIGHT);
JLabel RatingLabel = new JLabel("Rating", JLabel.RIGHT);
JLabel outputArea1Label = new JLabel("Details",JLabel.RIGHT);
JMenuBar bar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenu editMenu = new JMenu("Edit");
Vector DetailsV = new Vector();
Vector GeneraV = new Vector();
Vector RatingV = new Vector();
Vector TableLabelsV = new Vector();
JComboBox GeneraCB = new JComboBox(GeneraV);
JComboBox RatingCB = new JComboBox(RatingV);
JTable jt = new JTable(DetailsV,TableLabelsV);
//JScrollPane jsp = new JScrollPane(jt);
File GeneraInputFile = new File("/home/buddha/code/homeworkJava","GeneraFile.txt");
public homeworkJava()
{
super("DVD Database");
container.setLayout(layout);
readData(GeneraInputFile,GeneraV);
commands.setText("COMMANDS");
GeneraLabel.setLabelFor(GeneraCB);
RatingLabel.setLabelFor(RatingCB);
outputArea1Label.setLabelFor(jt);
box1.add(GeneraLabel);
box1.add(GeneraCB);
box2.add(RatingLabel);
box2.add(RatingCB);
box3.add(outputArea1Label);
box3.add(jt);
fileMenu.add(new JMenuItem("Open"));
fileMenu.add(new JMenuItem("Close"));
fileMenu.add(new JMenuItem("Search"));
editMenu.add(new JMenuItem("Cut"));
editMenu.add(new JMenuItem("Copy"));
editMenu.add(new JMenuItem("Paste"));
bar.add(fileMenu);
bar.add(editMenu);
TableLabelsV.add("Genera");
TableLabelsV.add("Rating");
TableLabelsV.add("Title");
TableLabelsV.add("Discription");
container.add(bar);
box1.setBackground(Color.white);
box2.setBackground(Color.white);
box3.setBackground(Color.white);
container.setBackground(Color.white);
c.fill = GridBagConstraints.BOTH;
c.gridx = 0;
c.gridy = 1;
c.gridwidth=4;
container.add(commands,c);
c.fill = GridBagConstraints.BOTH;
c.gridx=0;
c.gridy=2;
c.gridwidth=2;
container.add(box1,c);
c.fill = GridBagConstraints.BOTH;
c.gridx=1;
c.gridy=2;
c.gridwidth=0;
container.add(box2,c);
c.fill = GridBagConstraints.BOTH;
c.gridx=0;
c.gridy=4;
c.gridheight=9;
c.gridwidth=3;
container.add(box3,c);
setSize(250,250);
setVisible(true);
}
public static void main(String args[])
{
homeworkJava application = new homeworkJava();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void readData(File inputFile,Vector DataStorage)
{/////////////////work on this option
/* try
{
FileReader fr = new FileReader(inputFile);
BufferedReader in = new BufferedReader(fr);
while(in.readLine()!=null)
{
DataStorage.add(in.readLine());
}
}
catch(FileNotFoundException e)
{
System.out.println("File Disappeared");
}*/
}
}
Well, if you don't know about it already, http://java.sun.com/j2se/1.4.2/docs/api/index.html is the entire java API, and it's an incredibly useful resource. To answer your question, i'd look at c.insets. (A full description is somewhere in the above link.) As for the file processing, it would help if you'd say what sort of problems you're having.
container.getInsets(new Insets(0,0,0,0));
//and
container.Insets(0,0,0,0);
//and
Insets I = new Insets(0,0,0,0);
container.getInsets();
//and
Insets I = new Insets(0,0,0,0);
container.add(I);
Unfortunately there is no example code in any of my books or at that website you provided.
Good website by the way.
Do you have an example of it's implimentation?
Last edited by xviddivxoggmp3; 07-12-2004 at 12:54 PM.
Use GridBagConstraints.insets (c.insets = new Insets(...)).
Use JFrame.setJMenuBar so the bar will always be at the top.
Set the size of your window to get rid of the extra space. GridBagLayout will not stretch itself to fit larger windows.
I'm writing a program that is to read a file into a vector after being tokenized.
I'm receiving an error that I'm not sure how to correct.
unreported exception java.ioIOException; must be caught or declared to be thrown
while((tokens = new StringTokenizer(in.readLine()))!=null))
I'm assuming that the while condition is invalid.
Why is that?
The code for my read is in the function on the very bottom of the program.
Code is below.
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.io.*;
public class homeworkJava extends JFrame
{
Container container= getContentPane();
GridBagLayout layout= new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
Box box1 = Box.createVerticalBox();
Box box2 = Box.createVerticalBox();
Box box3 = Box.createVerticalBox();
JTextField commands = new JTextField(18);
JLabel GeneraLabel = new JLabel("Genera", JLabel.RIGHT);
JLabel RatingLabel = new JLabel("Rating", JLabel.RIGHT);
JLabel outputArea1Label = new JLabel("Details",JLabel.RIGHT);
JMenuBar bar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenu editMenu = new JMenu("Edit");
Vector DetailsV = new Vector();
Vector GeneraV = new Vector();
Vector RatingV = new Vector();
Vector TableLabelsV = new Vector();
JComboBox GeneraCB = new JComboBox(GeneraV);
JComboBox RatingCB = new JComboBox(RatingV);
JTable jt = new JTable(DetailsV,TableLabelsV);
JScrollPane jsp = new JScrollPane(jt);
File GeneraInputFile = new File("/home/buddha/code/homeworkJava","GeneraFile.txt");
public homeworkJava()
{
super("DVD Database");
container.setLayout(layout);
readData(GeneraInputFile,GeneraV);
commands.setText("COMMANDS");
GeneraLabel.setLabelFor(GeneraCB);
RatingLabel.setLabelFor(RatingCB);
box1.add(GeneraLabel);
box1.add(GeneraCB);
box2.add(RatingLabel);
box2.add(RatingCB);
box3.add(outputArea1Label);
box3.add(jsp);
fileMenu.add(new JMenuItem("Open"));
fileMenu.add(new JMenuItem("Close"));
fileMenu.add(new JMenuItem("Search"));
editMenu.add(new JMenuItem("Cut"));
editMenu.add(new JMenuItem("Copy"));
editMenu.add(new JMenuItem("Paste"));
bar.add(fileMenu);
bar.add(editMenu);
TableLabelsV.add("Genera");
TableLabelsV.add("Rating");
TableLabelsV.add("Title");
TableLabelsV.add("Discription");
bar.setBackground(Color.white);
box1.setBackground(Color.white);
box2.setBackground(Color.white);
box3.setBackground(Color.white);
container.setBackground(Color.white);
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 1;
c.weighty = 1;
c.gridx = 0;
c.gridy = 0;
c.gridwidth=3;
container.add(commands,c);
c.gridx=0;
c.gridy=1;
c.gridwidth=1;
container.add(box1,c);
c.gridx=2;
c.gridy=1;
c.gridwidth=0;
container.add(box2,c);
c.fill = GridBagConstraints.BOTH;
c.gridx=0;
c.gridy=2;
c.gridheight=6;
c.gridwidth=3;
container.add(box3,c);
setJMenuBar(bar);
setSize(300,300);
setVisible(true);
}
public static void main(String args[])
{
homeworkJava application = new homeworkJava();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void readData(File inputFile,Vector DataStorage)
{/////////////////work on this option
try
{
BufferedReader in = new BufferedReader(new FileReader(inputFile));
StringTokenizer tokens;
while((tokens = new StringTokenizer(in.readLine()))!=null)
{
while(tokens.hasMoreTokens())
DataStorage.add(tokens.nextToken());
}
}
catch(FileNotFoundException e)
{
System.out.println("File is not accessable");
}
}
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.