Trouble with gridbag layout
I have been experimenting with this container, but i cant work a couple of things out. I have set the size of my application quite large, 800, 600.
I am trying to get my end result to look somthing like this
SWIMMING
100M 200M 400M
So i have declared and initialised my components, and then i have done this to put them in the layout.
GridBagConstraints gridBagConstraintsx01 = new GridBagConstraints();
gridBagConstraintsx01.gridx = 0;
gridBagConstraintsx01.gridy = 0;
gridBagConstraintsx01.insets = new Insets(5,5,5,5);
cPane.add(lbSwimming, gridBagConstraintsx01); //JLabel
GridBagConstraints gridBagConstraintsx02 = new GridBagConstraints();
gridBagConstraintsx02.gridx = 0;
gridBagConstraintsx02.insets = new Insets(5,5,5,5);
gridBagConstraintsx02.gridy = 1;
gridBagConstraintsx02.gridwidth = 2;
gridBagConstraintsx02.fill = GridBagConstraints.BOTH;
cPane.add(eveSwim50M, gridBagConstraintsx02); //JButton
GridBagConstraints gridBagConstraintsx03 = new GridBagConstraints();
gridBagConstraintsx03.gridx = 1;
gridBagConstraintsx03.insets = new Insets(5,5,5,5);
gridBagConstraintsx03.gridy = 1;
gridBagConstraintsx03.gridwidth = 2;
gridBagConstraintsx03.fill = GridBagConstraints.BOTH;
cPane.add(eveSwim100M, gridBagConstraintsx03); //JButton
GridBagConstraints gridBagConstraintsx04 = new GridBagConstraints();
gridBagConstraintsx04.gridx = 2;
gridBagConstraintsx04.insets = new Insets(5,5,5,5);
gridBagConstraintsx04.gridy = 1;
gridBagConstraintsx04.gridwidth = 2;
gridBagConstraintsx04.fill = GridBagConstraints.BOTH;
cPane.add(eveSwim200M, gridBagConstraintsx04); //JButtonMy first problem is that everything has been put in the middle of my application, where i was hoping it would start in the top left. I thought that gridx0 and gridy0 would start it from this, but obviously this doesnt seem to be the case. How would i place it in the top left? My second problem is that my buttons are overlapping eachother and have not been seperated. I thought the fill would take care of this but once again it does not seemed to have worked. What would i use to give each button its space? Also, if you can see any improvements i could make, please advise me and i will make them.
Cheers for the help
I have changed it to be more like
lbMulti.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridwidth = 7;
gridBagConstraints.ipadx = 36;
gridBagConstraints.ipady = 6;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(27, 27, 0, 0);
getContentPane().add(lbMulti, gridBagConstraints);Getting closer to what i need, but i am going to take your advise and steer clear of gridbag, way too over the top. The only problem is that i cant really find another layout that will layout the way i want it too. I am checking in netbeans how each layout will look. If you can advise me what layout you prefere to use and then i could see if i could redesign my dialog around this.
cheers
Similar Messages
-
JPanel Positiong with Gridbag Layout Problem
Hi,
I'm desingning an UI in which I made a JFrame and set it Layout as gridBag layout. Now I have added Three JPanel in this JFrame.
The problem is that All the three JPanels are shown in center While I want to palce them in top left corner.
I have done this through NetBeans 4.0 in the layout coustomize option I've set them in first in the left top most, second in below of the first and so on but when I run the application The JPanel are shown in the center in this Particular position i.e first at the top in center second below to the fist and so on.
Kindly solve my this problem.
Regards,
Danish Kamran.To get better help sooner, post a SSCCE that clearly demonstrates your problem.
Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
db -
Trouble with liquid layout...
Hi,
I am trying to layout a site with CSS in a liquid style. This
is the first time im using a liquid layout and find it pretty
confusing.... The site is
here. The problem im currently
having is the block of text and image in the main content area (in
white with the guy with the megaphone) looks different in Internet
Explorer and Firefox and i cant work out why this is. Firefox
places it higher up the page and explorer places it lower down the
page....
How can i get them to be the same distance from the top? Any
ideas?
Thanks....Hello
You should validated your code. I think one of your problems
is that you might have a missing </div> tag. There are one or
two other easily repaired problems highlighted in the validator. I
think the bottom of your page needs to look like this:
<div id="footer">
<ul>
<li><a href="#">home</a></li>
<li><a href="#">about us</a></li>
<li><a href="#">lessons</a></li>
<li><a href="#">contact</a></li>
<li><a href="#">resources</a></li>
</ul>
</div>
</div>
</body>
</html>
If you want your page centered, you're missing margin: 0
auto; in your CSS for #wrapper; like so:
#wrapper {
background-color:#FFFFFF;
max-width:1000px;
min-width:810px;
padding:10px;
text-align:left;
width:90%;
margin: 0 auto;
You need to think whether using relative positioning is a
good idea if you don't need it. If you need to fiddle about with
placement of elements in your page I'd suggest researcing the float
property and the Box Model. There's plenty out there to read.
I add the caveat that I am clinging by my fingernails to the
level slightly above "Novice." I don't use relative positioning for
example, because I don't understand it!
Kind regards
Martin -
I recently just purchased a cd and I'm having trouble putting it on to my iPad / iPod probably due to the fact that I haven't used it in awhile, but the disk has been ripped to iTunes successfully but I'm lost at that step, whould any one be so kind to help me in this matter?
It goes onto your iPod the same way that the music you previously put on it did. So how did you do that?
The various options include:
Sync - you connect the iPod to your computer, iTunes sees it and Synchronises the iPod with iTunes (makes sure they are both the same).
Sync selected Playlists, albums and artists etc. - you choose which Playlists, albums, artists etc. are added to the iPod when it Syncs
Manually Manage - you have to drag songs etc from the iTunes Library onto your iPod.
If you connect the iPod to iTunes, a "Device" should appear, either on the left side of iTunes:
or as a small iPod button on the top right of iTunes:
Look on the Device/Music pane and check which choices you have previously set up. -
Gridbag Layout and Tabbed Panes
First off, I'm pretty new to Java, I started it around February as a school course, and it's been a pretty smooth ride. Recently, we started to code GUI, trying out different layouts and whatnot. I'm having a little trouble in this portion as our teacher did not really delve into it very much. My question concerns the GridBag layout within a panel of a tab (sorry if this is unclear, I'm talking about something that looks like this: http://www.codeproject.com/useritems/tabcontrol.asp). I don't know how to use GridBag constraints within a panel. What I used to do with GridBag was simply use some code that looked like (forgive me, this might not be very accurate): AddComponent button1(#, #, #, #) and define what each of those numbers meant later (first would be row, second would be column, third would be width, fourth would be height, for example). But now, with the tabs, each button, label, or any other control would be declared, then I would place a bunch of direct constraints after, like this:
JButton button1 = new JButton("1");
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 1;
constraints.gridheight = 1;then add them into the panel like this:
panel1.add(button1, constraints);However, I have tried making the buttons on top of each other, and other patterns, but it would just place the buttons next to each other within the panel. How do I make it so that the constraints work? Or rather, if they do work, what kinda things might mess it up? I think the problem is that I dunno how to make the constraints specific to that one button.
Also, how do I make each panel a certain size instead of each panel being as small as possible to contain anything within it.
I'm sorry if this all sounds very vague, I'd be more than happy to give you any needed information. Also, I'm not asking any of you to do my homework, I just need a little clarification or an example. Just in case, here's the code I'm working on: http://hashasp.mine.nu/paster/?1376. Be aware that there are no comments or anything, it's very bare. Also, the form may be a bit messy because I'm pretty much reusing code that was given to me, just manipulating it in a different way. Thanks a lot in advanced for your time in reading this.* GridBag_Demo.java
import java.awt.*;
import javax.swing.*;
public class GridBag_Demo extends JFrame {
public GridBag_Demo() {
setTitle("GridBag Demo");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setSize(400,300);
setLocationRelativeTo(null);
GridBagConstraints gridBagConstraints;
jTabbedPane1 = new JTabbedPane();
jPanel1 = new JPanel();
jButton1 = new JButton();
jButton2 = new JButton();
jButton3 = new JButton();
jPanel1.setLayout(new GridBagLayout());
jButton1.setText("jButton1");
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.insets = new Insets(2,2,2,2);
jPanel1.add(jButton1, gridBagConstraints);
jButton2.setText("jButton2");
gridBagConstraints.gridy = 1;
jPanel1.add(jButton2, gridBagConstraints);
jButton3.setText("jButton3");
gridBagConstraints.gridy = 2;
jPanel1.add(jButton3, gridBagConstraints);
jTabbedPane1.addTab("tab1", jPanel1);
getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
public static void main(String args[]) {
new GridBag_Demo().setVisible(true);
private JButton jButton1;
private JButton jButton2;
private JButton jButton3;
private JPanel jPanel1;
private JTabbedPane jTabbedPane1;
} -
The updated iPhoto program is cumbersome. I am trying to create a Christmas card and can't figure out how to get the fold of the card on the left and not on the top of the card. I had no trouble with this for the past two years. Can someone help?
Click on the Layout button lower right and choose a Vertical lyout from the dropdown
-
I am really in trouble with AP Div-How do I fix it on the web?
Hi,
I am really in trouble with my website. I have added some pictures and text on top of Fireworks Image and have published it on the website.
But the concern is, when I zoom in & zoom out, I can see the previous text on the screen and also the picture and texts I have added using Ap Div tag are scattered moving all to the left when I zoom out. Can someone help me how to fix this in one particular place so that it doesn't move when I zoom in or zoom out!!! I am using Adobe Dreamweaver CS3, if this will help.
Appreciate your sincere help on this.
Thanks in advance.Frankly, there's a lot that is wrong with that page:
1. Most of your content is in the images - this means that you will get very poor search engine ranking
2. Your extensive use of absolute positioning for layout - this means that when you enlarge the text size in the browser, you will have overflow problems on the page (for example, the terrible problems at the bottom of the page)
3. You have used tables for layout - this is because of your use of Fireworks to create the HTML
Each of these problems is solvable but none of them are solvable easily without a redesign of the page. A web page should be built from the top down, stacking content containers (i.e., <div>, <section>, <article>, <aside>, etc.) vertically or floating them horizontally or both. These containers would be loaded with the text content of the page, and images would be used only for cosmetic appearance. Using CSS to style/locate the content will allow you to completely move away from tables for layout. Most typical pages can be created without the use of absolute positioning which should be used only for special purposes, not for layout of the page elements. -
JTextArea & Gridbag layout - max size of control
Hello everyone:
I am currnetly using a JTextArea with the Gridbag layout. I want to limit the size of the JTextArea. Found an article when I did a "search" that says the size is actually controlled by the layout manager. Have tried setMaximunSize(), no luck. It appears the layout manager ignores this. The problem I am having is that I can set the size I want, however if the user types a lot of text in to the JTextArea, the control expands and over and "pushes" the controls below it down. How do I keep the layout manager from allowing this to happen?
Thanks in advance, BartHello everyone:
I am currnetly using a JTextArea with the Gridbag
layout. I want to limit the size of the JTextArea.
Found an article when I did a "search" that says the
size is actually controlled by the layout manager.
Have tried setMaximunSize(), no luck. It appears the
layout manager ignores this. The problem I am having
is that I can set the size I want, however if the user
types a lot of text in to the JTextArea, the control
expands and over and "pushes" the controls below it
down. How do I keep the layout manager from allowing
this to happen?
Thanks in advance, Bart Do you wish to allow the user to enter as much text as he or she likes? If so, wrap the JTextArea in a JScrollPane and set the preferred size of the JScrollPange to the area you'd like the pane to consume. It'll listen, no doubt. :) -
I'm in trouble with copy paste some text from Word to DW mx 2004
I'am a new developer in webdesign. I'm doing my first site to
a cliente. I'm in trouble with copy paste some text from Word to DW
mx 2004. In the Edit / Preferences / General category i have the
spelling dictionary in Portuguese (Brasilian). If I wrote the text
in Portuguese directly from DW i can see the letters with ( ç
ã é ... ) and in the browser testing ( IE 6.0.2 with sp2
and FireFox 1.0.7 ), but with copy paste from the text in Word in
Portuguese when i bring it to DW i can see the ( ç ã
é ... ) in the beginnig but in the Browsers testing i can't,
and then after a while i lose the ( ç ã o ...). Can
anyone help me !?
I need the work finish in next monday. Thanks a lot.Your line breaks will most likely be incorrect if you don't turn on the Japanese Composer.
It is almost absolutely impossible to accomplish your goal without having a font - any font - installed on your system that has that glyph. However, if it's showing up in Word, than means that you must have that glyph installed, right? What font are you trying to use in InDesign? You might already know that Word will auto-substitute fonts when it encounters a missing glyph, so we really don't know what font is being used to render that one glyph. The whole sentence might be in MS Mincho but one glyph might be pulled from another font if MS Mincho doesn't have that glyph.
That being said, you're going to break it if you don't know how to set Japanese type in ID. It's not something where you can just copy text out of email and paste into your English layout. -
Trouble with Exported .pdf Files
I created three 20"x30" one-page documents (with iPhoto-sourced images) which saved as 24.7 MB, 19.4 MB, and 10.7 MB files, respectively. I needed to send JPEG files to my service provider for high-resolution prints. Since Pages '08 doesn't have a JPEG-export option, I exported each of them as .pdf files. My plan was to open the .pdf files in Photoshop and save them down as .jpg files. The same path had worked fine with a fourth Pages '08 layout of a 2.25"x3.75" document. With the three 20"x30" files, however, I ran into trouble.
My laptop didn't have enough memory to open the exported .pdf files in Photoshop Elements without suffering some image gray-out. I didn't think that was a problem until we discovered that my service provider couldn't open the files at all (running the current Photoshop on a souped-up system). Arghhh.
I switched to a service provider who can print straight from the .pdf files, but that also brought trouble. Though I could open the files easily in Acrobat 5.0, and they looked great, the service provider (running the current full version of Acrobat) could not open them; all he got was what looked like a blank page.
I don't think the trouble is related to file size, as the business-card document which sailed through without trouble saved as an 11.2 MB Pages file.
Could it be sheet size? That's the only thing I can figure. And why would the files open in Acrobat 5.0 without trouble, but not in the current Acrobat (or Acrobat Professional, which we also tried)?
I ended up "printing" the Pages files as "Save PDF to iPhoto," then exporting the iPhoto image as a maximum-resolution JPEG. The only trouble with that route was that the best I could get was a 200 dpi. When I went through Photoshop (instead of iPhoto) with the business card file, I ended up with a 300 dpi file.
Am I missing something obvious here? Any help would be appreciated.Hi,
I don't know if this is the correct answer, but you can open a PDF in Preview and save the document as a JPEG and JPEG-2000. I know that Leopard will also have some neat functionality about this as well. You might also want to look at printing as a postscript file rather than a PDF and then open in Photoshop. I talked with a FEDEX/Kinkos employee yesterday about my book at he stated that Macs use 1.5 while Adobe's Acrobat is 1.7. Leopard should also fix this, but it may not help right now.
HTH -
Possible Problem/Bug In GridBag Layout ????
I've done hundreds of Gridbag layouts in the past 2 years and just noticed this weird little behavior today.....
Basically what I'm trying to do is arrange panels like this.....
+--------+--------+--------+
| | | |
| A | B | C |
| | | |
+--------+----+---+--------+
| | |
| D | E |
| | |
+-------------+------------+The obvious thing to do is to
o make the gridwidths of
B, D, E = 2
A, C = 1
D and E should each share one unit of
B's 2 width.
Tried it in my code with my real UI and it didn't work, so then I tested it
out using a Gridbag tool where you can set parameters on the fly quickly and
surely enough it did not work there either.
The GridBagLayout is refusing to split B into 2 portions for the 2nd row
to use in an unalligned fashion. I either get
+--------+--------+--------+
| | | |
| A | B | C |
| | | |
+--------+----+---+--------+
| | |
| D | E |
| | |
+--------+-----------------+ or
+--------+--------+--------+
| | | |
| A | B | C |
| | | |
+--------+----+---+--------+
| | |
| D | E |
| | |
+--------+--------+--------+ depending on the order in which I add my panels to the layout.
even though my gridx, gridy and widths and heights are properly set for
obtaining the result I want.
Can someone confirm that this is a bug in the GridBagLayout or share the trick for
getting around this?Thanks for the reply - I can set the weights however
I wish and I never see box D extending even one pixel
into the A-B boundary.This does what you say...
import java.awt.*;
import javax.swing.*;
public class TestFrame extends JFrame {
public TestFrame() {
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.BOTH;
gbc.weighty = 0.5;
panel.add(new JButton("A"), gbc);
gbc.gridx = 1;
gbc.gridwidth = 2;
panel.add(new JButton("B"), gbc);
gbc.gridx = 3;
gbc.gridwidth = 1;
panel.add(new JButton("C"), gbc);
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 2;
gbc.weightx = 0.5;
panel.add(new JButton("D"), gbc);
gbc.gridx = 2;
panel.add(new JButton("E"), gbc);
getContentPane().add(panel);
setSize(400, 300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
public static void main(String[] args) {
TestFrame frame = new TestFrame();
frame.setVisible(true);
}But i'm sure it's not a satisfactory layout because button A does not want to resize horizontally at all. But of course, a mix of grid layouts does the trick:
import java.awt.*;
import javax.swing.*;
public class TestFrame extends JFrame {
public TestFrame() {
JPanel panel = new JPanel(new GridLayout(2, 1));
JPanel top = new JPanel(new GridLayout(1, 3));
top.add(new JButton("A"));
top.add(new JButton("B"));
top.add(new JButton("C"));
panel.add(top);
JPanel buttom = new JPanel(new GridLayout(1, 2));
buttom.add(new JButton("D"));
buttom.add(new JButton("E"));
panel.add(buttom);
getContentPane().add(panel);
setSize(400, 300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
public static void main(String[] args) {
TestFrame frame = new TestFrame();
frame.setVisible(true);
} -
Need help with Page Layout and Background Scaling
hello, everyone.
I am in the process of designing a new website for myself,
and while I was researching nicely designed pages to use as
inspiration, I stumbled upon this site:
http://www.jeffsarmiento.com/
obviously, the design is very impressive, but it also
incorporates a lot of web mechanics that I have been trying to
figure out, so I will use this page as an example.
one thing I need help with is backgrounds. as you can see in
the posted website, the creator used a seamlessly tiled paper
texture to display the bulk of his content on. also make not of the
pattern that is located to the left of the paper texture. how do I
create seamless backgrounds like this that will scale to fit any
amount of content or any resolution? I can't imagine that the guy
that made that site created a new size background every time he
made an update, so there has to be an easier way.
the second thing that I am having trouble with is general
site layout. I have read that most sites used series of invisible
tables to organize there content, but when I open the source of
this page in dreamweaver, he was using something different. div
tags? should I be using these? who do I use them? are there any
general layout tips that someone could pass on to me? perhaps a
link to a good tutorial?
please help me. i am very confused.
thanks so much.IMO not a good site to emulate. To wit:
Top background image:
http://www.jeffsarmiento.com/images/bg-top.jpg;
745px
x 350px 137K
Main background image:
http://www.jeffsarmiento.com/images/bg-tile.jpg;
745px x 950px 130K
Total page size: 454K (Check here:
www.websiteoptimization.com)
Website usability experts routinely recommend a maximum page
size of ~80K
Check out the We We Scale @ www.FutureNowInc.com/wewe/ where
they suggest,
"You speak about yourself approximately 0,003 times as often
as you speak
about your customers. Might that have an impact on your
effectiveness?"
That is 100% consistent with the #1 Web Design mistake:
"Believing people
care about you and your web site." or to phrase more
expansively, "Our site
tries to tell you how wonderful we are as a company, but not
how we're going
to solve your problems."
www.sitepoint.com has some excellent books on making a
website actually
attractive and usable at the same time.
Walt
"beWILLdered_" <[email protected]> wrote in
message
news:[email protected]...
> hello, everyone.
> I am in the process of designing a new website for
myself, and while I was
> researching nicely designed pages to use as inspiration,
I stumbled upon
> this
> site:
>
http://www.jeffsarmiento.com/
> obviously, the design is very impressive, but it also
incorporates a lot
> of
> web mechanics that I have been trying to figure out, so
I will use this
> page as
> an example.
> one thing I need help with is backgrounds. as you can
see in the posted
> website, the creator used a seamlessly tiled paper
texture to display the
> bulk
> of his content on. also make not of the pattern that is
located to the
> left of
> the paper texture. how do I create seamless backgrounds
like this that
> will
> scale to fit any amount of content or any resolution? I
can't imagine that
> the
> guy that made that site created a new size background
every time he made
> an
> update, so there has to be an easier way.
> the second thing that I am having trouble with is
general site layout. I
> have
> read that most sites used series of invisible tables to
organize there
> content,
> but when I open the source of this page in dreamweaver,
he was using
> something
> different. div tags? should I be using these? who do I
use them? are there
> any
> general layout tips that someone could pass on to me?
perhaps a link to a
> good
> tutorial?
> please help me. i am very confused.
>
> thanks so much.
> -
Gridbag layout problem on a tabbedpane
I am not sure whether we can do this or not but, I am trying to have a gridbag layout on a TabbedPane object.
I have a JFrame on which I am adding a TabbedPane object called "t" and on this TabbedPane I am adding a tab called "Insert" which is an object of class "Insert Data". Then, I add the TabbedPane t on the Container cp, which is inside the JFrame.
In the InsertData Class (a JPanel), I need to have the gridbag layout. With this gridbag layout object, I am trying to place different objects like buttons, at various places, on this JPanel. But nothing moves on this panel.
In short, please let me know how can I have a gridbag layout on a Tabbedpane.
The Main Class is as follows:
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Main extends JFrame implements ActionListener, ChangeListener{
Main(){
setPreferredSize(new Dimension(1200,600));
Container cp = getContentPane();
JTabbedPane t = new JTabbedPane();
// insert
InsertData insertOptions = new InsertData();
t.addTab("Insert",insertOptions);
cp.add(t);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
@Override
public void stateChanged(ChangeEvent arg0) {
// TODO Auto-generated method stub
public static void main(String args[]){
new Main();
}The InsertDataClass is:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class InsertData extends JPanel{
InsertData(){
setPreferredSize(new Dimension(1200,600));
setBackground(Color.blue);
//setLayout(new GridBagLayout());
GridBagLayout gb = new GridBagLayout();
setLayout(gb);
GridBagConstraints c = new GridBagConstraints();
//c.insets = new Insets(2, 2, 2, 2);
//JPanel p1= new JPanel();
//p1.setPreferredSize(new Dimension(200,200));
JButton b1 = new JButton("here i am!!!");
//p1.add(b1);
//c.fill = GridBagConstraints.HORIZONTAL;
//c.anchor = GridBagConstraints.WEST;
c.gridx=0;
c.gridy=1;
add(b1,c);
}how can I have a gridbag layout on a Tabbedpane.Huh? You post an example with just one JButton and no weightx / weighty set and you expect others here to be able to see a problem with your layout?
Also, there's needless, unused code that is just clutter -- like the unimplemented ActionListener and ChaneListener. Recommended reading: [SSCCE (Short, Self Contained, Compilable and Executable, Example Program)|http://mindprod.com/jgloss/sscce.html].
Finally, I don't see any need whatsoever to extend JFrame and JPanel as you are not introducing any new behavior of either. Always favor composition over inheritance.
I plugged in some code I had used for someone else's GridBagLayout problems and this will show you that there's no difference in using GridBagLayout in a tabbed pane component or anywhere else.import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.*;
public class GridBagInTabbedPane {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new GridBagInTabbedPane().makeUI();
public void makeUI() {
Font fontButton = new Font("Arial", Font.BOLD, 10);
Font fontLabel = new Font("Arial", Font.BOLD, 15);
JLabel labelEnter = new JLabel("Enter sentences in the text area ");
labelEnter.setFont(fontLabel);
JTextArea textArea = new JTextArea();
textArea.setPreferredSize(new Dimension(630, 280));
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setMinimumSize(new Dimension(630, 280));
JLabel labelDuplicates = new JLabel("Duplicates will appear here");
labelDuplicates.setMinimumSize(new Dimension(650, 30));
labelDuplicates.setFont(fontLabel);
JButton buttonDisplay = new JButton("Display Map");
buttonDisplay.setFont(fontButton);
JButton buttonClear = new JButton("Clear");
buttonClear.setFont(fontButton);
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
gbc.fill = GridBagConstraints.NONE;
gbc.anchor = GridBagConstraints.CENTER;
gbc.insets = new Insets(5, 5, 5, 5);
gbc.weightx = 0.5;
panel.add(labelEnter, gbc);
gbc.gridy = 1;
gbc.fill = GridBagConstraints.BOTH;
gbc.weighty = 0.5;
panel.add(scrollPane, gbc);
gbc.gridy = 2;
gbc.fill = GridBagConstraints.NONE;
gbc.weighty = 0.0;
panel.add(labelDuplicates, gbc);
gbc.gridy = 3;
gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.EAST;
panel.add(buttonDisplay, gbc);
gbc.gridx = 1;
gbc.anchor = GridBagConstraints.WEST;
panel.add(buttonClear, gbc);
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.add(panel);
JFrame frame = new JFrame();
frame.add(tabbedPane);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}db -
Trouble with PDF fonts - fields only
We're having trouble with our PDFs once the data is merged into the PDF template. All of the merged data appears cut in half in the form fields so only the top half of the letters are shown; the rest of the document is fine. We think this could be due to a font issue, but loading different fonts haven't seemed to make any difference. Could this be caused by anything besides the fonts?
Thanks!
KHKlye
Pdf is designed for presenting information graphically to reduce the file size. This reduction is achieved by making it an uneditable - something that comes in handy if you don't want people to alter your content.
You can (using a pdf writter) create pdf forms where information can be added in to a text field or box. However if you want to edit the content from a pdf file then you could select the text and copy and paste it in to a document like Pages or Word and then re-export when you're finished.
But I'm affraid you can't edit pdf as such - this is the case on Macs and PCs. If you need to edit documents on different platforms then you'll need to find a common editor. There's Office for Mac (student teacher versions) or you could try OpenOffice Org - it's free, works on both Macs and PCs, and will convert most Word documents provided there's not too many tables or a complex layout format.
Hope this helps
Stu -
Gridbag layout continues to confound me...
I am having problems with the gridx and gridy constraints when trying to use gridbag layout. They seem to have no effect when I use them. The button always appears in the top left of the panel. Other constraints seem to work as expected.
For example: c2.fill = GridBagConstraints.BOTH; will fill up the entire panel with my button.
Any advice on what I am doing wrong this time?
Thanks
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JFrame;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.Color;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.text.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
public class Question
public JPanel test()
JPanel testPanel = new JPanel(new GridBagLayout());
GridBagConstraints c2 = new GridBagConstraints();
c2.insets = new Insets(5,5,5,5);
c2.weightx = 1.0;
c2.weighty = 1.0;
c2.anchor = c2.NORTHWEST;
JButton redButton = new JButton("Button");
c2.gridx = 2;
c2.gridy = 2;
//c2.fill = GridBagConstraints.BOTH;//this works as expected
testPanel.add(redButton,c2);
return testPanel;
public Container createContentPane()
//Create the content-pane-to-be.
JPanel contentPane = new JPanel(new BorderLayout());
contentPane.setOpaque(true);
return contentPane;
private static void createAndShowGUI()
//Create and set up the window.
JFrame frame = new JFrame("question");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
Question demo = new Question();
frame.setContentPane(demo.createContentPane());
frame.add(demo.test());
//Display the window.
frame.setSize(400, 400);
frame.setVisible(true);
public static void main(String[] args)
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable()
public void run()
createAndShowGUI();
}//end main
}//end QuestionGridBagLayout keeps zero width/height grid for non-existant component for the grid.
You could override this behavior by using GBL's four arrays as shown below.
However, in order to get the desired layout effect, using other layout manager, e.g. BoxLayout and/or Box, is much easier and flexible as camickr, a GBL hater, suggests.
Anyway, however, before using a complex API class as GBL, you shoud read the documentation closely.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Question{
// you may adjust these values for your taste
static final int rowHeight = 100;
static final int colWidth = 100;
static final double rowWeight = 1.0;
static final double colWeight = 1.0;
public JPanel test(){
GridBagLayout gb = new GridBagLayout();
gb = keepAllRowsAndColumns(gb, 3, 3);
JPanel testPanel = new JPanel(gb);
GridBagConstraints c2 = new GridBagConstraints();
c2.insets = new Insets(5,5,5,5);
c2.weightx = 1.0;
c2.weighty = 1.0;
c2.anchor = c2.NORTHWEST;
JButton redButton = new JButton("Button");
c2.gridx = 2;
c2.gridy = 2;
// c2.fill = GridBagConstraints.BOTH;//this works as expected
testPanel.add(redButton,c2);
return testPanel;
GridBagLayout keepAllRowsAndColumns(GridBagLayout g, int rn, int cn){
g.rowHeights = new int[rn];
g.columnWidths = new int[cn];
g.rowWeights = new double[rn];
g.columnWeights = new double[cn];
for (int i = 0; i < rn; ++i){
g.rowHeights[i] = rowHeight;
g.rowWeights[i] = rowWeight;
for (int i = 0; i < cn; ++i){
g.columnWidths[i] = colWidth;
g.columnWeights[i] = colWeight;
return g;
private static void createAndShowGUI(){
JFrame frame = new JFrame("question");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Question demo = new Question();
frame.getContentPane().add(demo.test(), BorderLayout.CENTER);
frame.setSize(400, 400);
frame.setVisible(true);
public static void main(String[] args){
javax.swing.SwingUtilities.invokeLater(new Runnable(){
public void run(){
createAndShowGUI();
}
Maybe you are looking for
-
XML to PLAIN - urgent help needed
Hello everybody! I have a ftp receiver adapter; in this adapter a xml file should be converted to a plain text file. The structure looks like this: <ns0:MFG_ORDERS xmlns:ns0="urn:test.com:edi:test"> <HEADER> <So_recordtype>SOHD</So_recordtype> <S
-
hi , 1. if i am doing only a file to idoc scenario do i need a rfc dest from SAP to XI if yes why?? 2. if i am doing a idoc to file scenario do i neeed rfc dest and port from XI to SAP if yes why??
-
How can I perform a factory reset on an Apple TV over a network from another room?
I would like to either perform a factory reset or erase user account information on a third generation Apple TV located in another room preferably over a network. This would allow me to manage the devices off site over IP with different people using
-
Change the price variance account
Hi, We have an issue here. When we do posting using MB1B, movement type 309 to transfer from 1 material A ($5.00) to another material B($4.00), there is a price variance $1.00 auto post to a GL account C, and the $5.00 and $4.00 will post to the stoc
-
Landscape planning with BI and APO
Hello all, This is more of planning question rather than issue. If you have upgraded your R/3 system first to Unicode before the BI and APO/SCM - how did you manage the interface testing within BI and APO, especially on how to avoid impact on existin