Grid abck layout problem using swing components

JScrollPane jsp1 = new JScrollPane(table1,k,i);
JPanel ja = new JPanel();
JCheckBox c1 = new JCheckBox();
JCheckBox c2 = new JCheckBox();
JCheckBox c3 = new JCheckBox();
JLabel j = new JLabel("Button");
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
ja.setLayout(gbl);
gbc.gridwidth = 10;
gbc.gridheight = 10;
gbc.gridx = 0;
gbc.gridy = 0;
gbl.setConstraints(j,gbc);
add(j);
gbc.gridx = 1;
gbc.gridy = 1;
gbl.setConstraints(c2,gbc);
add(c2);
gbc.gridx = 2;
gbc.gridy = 2;
gbl.setConstraints(c3,gbc);
add(c3);
gbc.gridx = 3;
gbc.gridy = 3;
gbl.setConstraints(jsp1,gbc);
add(jsp1);
this my code for grid bag layout but when i run this code it is showing only empty panel..no components..
of course iam not posting entire code of tis class..because it is lenghty..
regards,
sam

Well, you set JPanel ja's layout to GridBagLayout, but it appears your adding the components to the parent, eg. add(j) should be ja.add(j) if you want it on JPanel ja. This is true for all your component adds.
By the you can combine the setConstraints( ) and add calls: ja.add(j, bgc);
Hope that helps.
Cheers
DB

Similar Messages

  • I can't use swing components in my applets

    When I write an applet without any swing components, my browser never has any trouble finding the classes it needs, whether they're classes I've written or classes that came with Java. However, when I try to use swing components it cannot find them, because it is looking in the wrong place:
    On my computer I have a directory called C:\Java, into which I installed my Java Development Kit (so Sun's classes are stored in the default location within that directory, wherever that is), and I store my classes in C:\Java\Files\[path depends on package]. My browser gives an error message along the lines of "Cannot find class JFrame at C:\Java\Files\javax\swing\JFrame.class"; it shouldn't be looking for this non-existent directory, it should find the swing components where it finds, for example, the Applet class and the Graphics class.
    Is there any way I can set the classpath on my browser? Are the swing components stored separately from other classes (I'm using the J2SE v1.3)?
    Thanks in advance.

    Without having complete information, it appears that you are running your applets using the browser's VM. Further, I assume you are using either IE or Netscape Navigator pre-v6. In that case, your browser only supports Java 1.1, and Swing was implemented in Java 1.2. You need to use the Java plug-in in order to use the Swing classes (see the Plug-in forum for more information), or else download the Swing classes from Sun and include them in your CLASSPATH.
    HTH,
    Carl Rapson

  • Using Swing Components in JSP

    Hi,
    I regret that I do not have a very specific problem here. However, I am wondering if there is a way to display Swing components, such as a panel, on a web page using JSP. If so, are there any tutorials on such a practice? Or would something like this be included in a general tutorial?
    Thanks,
    Dan

    You'll have to use a JApplet.

  • How to use Swing Components in  JavaFX

    Hi All,
    I am new to JavaFx. I am trying to use java swing components in javafx.
    I found a sample program in net and tried it. But it shows compile time error.
    Code:
    MySwingComponent .fx
    import javafx.ext.swing.SwingComponent;
    import javax.swing.JComponent;
    import javax.swing.JButton;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    * @author nandha
    class MySwingComponent extends SwingComponent{
    var button: JButton;
    public var text: String on replace {
    button.setText(text);
    public var action: function();
    override protected function createJComponent () : JComponent {
    button = new JButton();
    button.addActionListener(ActionListener {
    public override function actionPerformed(e:ActionEvent){
    action();
    return button;
    The above code shows no error.
    Test SwingButton.fx
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import swingcomponents.MySwingButton;
    * @author nandha
    Stage {
    title: "Swing Button Example"
    scene: Scene {
    width: 250
    height: 80
    content: [
    MySwingButton{  // error message: imcompatible type. found MySwingButton. Required javafx.scene.Node[]
    text: "Click Me!"
    action: function(){
    println("Hello World!");
    This code which used the MySwingButton shows error: imcompatible type. found MySwingButton. Required javafx.scene.Node[] - where i have added the MySwingButton.
    Please help me to fix the error.
    Thanks &Regards,
    Nandha K

    Hi Sasa,
    First thanks for your reply.
    I found the problem and have fixed.
    Problem:
    There is no class MySwingButton in the package swingcomponents. Its MySwingComponent that i should have used, which is a big mistake that i have done. To my surprise i don't know NetBeans didn't show any error message at that line.
    Thanks & Regards,
    Nandha K

  • Layout problem in Swing.

    Hi,
    I have made an application in Swing containing Grouplayout on the panel.
    On that panel I keep on dragging and dropping Swing Components like push button, textboxes etc and then save it using XMLEncoder i.e. I save the complete panel.
    After saving, when I recall them using XMLDecoder, the layout is completely different.
    I mean when I drag and drop the components to make a login screen and save them and when I open the same file they all appear in different layout.
    Can anybody help me solve this issue.
    Thanks and Regards,
    Hi

    If you have a layout that requires drag and drop support then you can't use a layout manager. You need to use a "null" layout so you can randomly position components.

  • Layout Problem in swings

    I have an Layout problem. My Applications consists of a label and a panel in which some more labels are present.
    The panel should contain the scrollbar in order to view all the label that excced the size of the panel.This label and a panel should be adjacent to each other.
    My problem is, I am not getting the scroll bar to the panel when I am adding the label that excced the size of the panel, when I am adding the label adjacent to this label.

    Did you use JScrollPanel? If not, use it.

  • How to implement hyperlink in java using swing components

    hi.....
    pls help me to find out solution
    how to implement hyperlink in java using swing components

    I've got the same problem here.
    I want to implement a HyperlinkListener to a JLabel. (Unlike suggested above, it is only supported by JEditorPane and not JLabel)
    The goal is, that if a user clicks on a Link in a JLabel, the standard browser opens and displays that page.
    Can somebody please help?
    My ultimate goal would be to also be able to add clickable HyperLinks in ToolTip texts, but i guess that'd be even more complicated.

  • Can I Use Swing Components in a JSP Page

    Hi,
    Can I use Swing Componnents in a JSP Page.If so,Can anybody provide with a sample code.
    Thanks.

    hi,
    I wanted to use the JTabbedPane for tab buttons in my
    Jsp Page.Is that possible?I am afraid that you can't.
    As for GUI (graphics) in the HTML page you can use only the html form elements (but you should simulate other behaviours by dynamically reloading the page).-
    Ionel.

  • Need suggestion regarding Layout Manager using Swing in Java

    I have developed a swing application where i am having problem with selecting the right layout manager.
    I am attaching the file where it contains the method for addingComponents to the Content Pane. But, the code that i have written
    contains lot of spaces between first panel and second panel and so forth.
    Please suggest.
    <<Code>>
    public void addComponentsToPane(Container contentPane) {
              this.contentPane = contentPane;
    //          File Panel
              JPanel jfile1panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
              JPanel jfile2panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
              JPanel jfile3panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
              JLabel jfile1 = new JLabel("Select File:");
              jtfile1 = new JTextField(50);
              jbfile1 = new JButton("Button1");
              jfile1panel.add(jfile1);
              jfile1panel.add(jtfile1);
              jfile1panel.add(jbfile1);
              jbfile1.addActionListener(this);
              JLabel jfile2 = new JLabel("Select File:");
              jtfile2 = new JTextField(50);
              jbfile2 = new JButton("Button2");
              jfile2panel.add(jfile2);
              jfile2panel.add(jtfile2);
              jfile2panel.add(jbfile2);
              jbfile2.addActionListener(this);
              JLabel jfile3 = new JLabel("Select File:");
              jtfile3 = new JTextField(50);
              jbfile3 = new JButton("Button3");
              jfile3panel.add(jfile3);
              jfile3panel.add(jtfile3);
              jfile3panel.add(jbfile3);
              jbfile3.addActionListener(this);
              //Button Panel
              JPanel jbuttonpanel = new JPanel();
              jbuttonpanel.setLayout(new FlowLayout(FlowLayout.CENTER));
              JButton jbcmd1 = new JButton("Submit");
              JButton jbcmd2 = new JButton("Cancel");
              jbuttonpanel.add(jbcmd1);
              jbuttonpanel.add(jbcmd2);
              jbcmd1.addActionListener(this);
              jbcmd2.addActionListener(this);
              //Content Pane               
              contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
              contentPane.add(jfile1panel);
              contentPane.add(jfile2panel);
              contentPane.add(jfile3panel);
              contentPane.add(jbuttonpanel);
    }

    But, the code that i have written contains lot of spaces between first panel and second panel and so forth.use pack(), see if it makes a difference
    as you're using FlowLayout, make the frame not resizable

  • New - can't use Swing components????

    I downloaded jdk-1_1_8_009-win.exe and installed and I'm merrily learning Java - except I don't have the javax.swing.* classes in this download (when I look in \lib\classes.zip).
    I have repeatedly tried downloading the SDK 1.3.1 and Java Foundation Classes (JFC), but all I get is Page Not Found over and over.
    This is getting freaking frustrating. What am I supposed to do? All I'm trying to do is create a JFrame with a JButton, and continue from there. Why isn't the Swing stuff in their latest JDK download?
    Thanks for reading a dumb question from a beginner!

    Why isn't the Swing stuff in their latest JDK download?It is! The problem is that you downloaded an obsolete JDK version (1.1.8), and javax.swing did not appear until version 1.2.
    What am I supposed to do? Download the lastest version of the SDK.
    http://java.sun.com/j2se/1.4/download.html

  • Calendar layout problem using iPhoto 09

    With the 6 photo layout option the largest photo started out as a vertical, just like the menu selection suggests. However, after replacing some of the other photos, the desired vertical became a horizontal. The actual image requires the portrait style (vertical), but we cannot get it back. Can anyone offer suggestions how to return that photo to a vertical?

    it probably depends on the order you place the photos - see liz Castro's web site for a general discussion - http://www.iphotobookthemes.com/pmwiki.php?n=Main.OriginalOrientation - probably the only way is to experiment
    LN

  • Swing components not displaying correctly in JApplet

    Hello everyone,
    I have experienced some strange problems using Swing components on JApplets. Maybe I missed some documentation somewhere and someone can help me out.
    The problem is that when I add components like JButtons,
    JCheckboxes, JRadioButtons, JTextFields, JPasswordFields,
    and JComboBoxes to JApplets, when I view the applet, the
    component does not become visible until I move the mouse
    pointer over it in the case of buttons. For the JComboBox I have
    to hit the mouse key many times on the component to see the list. Has anyone experienced problems like these? Thanks.
    Keith

    check what is in ur paint(Graphic g) method. if it does nothing, remove the paint(Graphic g) method. if it has some codes, double check ur codes.

  • Jre 15.0_22/Linux - Swing components error when using GTKLookAndFeel

    Hello,
    I'm not sure if it's a JRE bug or what, but on Linux platforms our applet fails when using swing components using the GTKLookAndFeel.
    To demonstrate/test, I have the ff test applet:
    import java.applet.Applet;
    import javax.swing.UIManager;
    import javax.swing.UnsupportedLookAndFeelException;
    public class TestApplet extends Applet {
      @Override
      public void init() {
        super.init();
        test();
      public static void main(String[] args) {
        (new TestApplet()).test();
      public void test() {
        try {
          String className = UIManager.getSystemLookAndFeelClassName();
          System.out.println(className);
          javax.swing.LookAndFeel laf = (javax.swing.LookAndFeel) this.getClass().forName(className).newInstance();
          UIManager.setLookAndFeel(laf);
          System.out.println("setting classloader");
          UIManager.put("ClassLoader", this.getClass().getClassLoader());
          UIManager.getLookAndFeelDefaults().put("ClassLoader", this.getClass().getClassLoader());
        } catch (ClassNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (InstantiationException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IllegalAccessException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (UnsupportedLookAndFeelException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        System.out.println(UIManager.getLookAndFeelDefaults().getUIClass("javax.swing.JTextField"));
        UIManager.getLookAndFeelDefaults().getUI(new javax.swing.JTextField());
    }The system look and feel here is GTKLookAndFeel. The problem is that the getUI() call in the last line is returning null and I can see in the console:
    UIDefaults.getUI() failed: no ComponentUI class for: javax.swing.JTextField
    java.lang.Error
    .. etc.
    This is happening for different swing classes, I just used JTextField here as a simple test case.
    This only happens if the applet is run from the browser (via the java plugin). If I run the above code from the command line, there is no error raised, and the actual component UI class is a Synth class.
    This is only happening for us in Java 1.5.0_22 on Linux...on 1.5.0_15 and 1.6+ it seems to be fine. I'm using the 1.5.0_22 JDK downloaded from Sun.
    Anyone have any idea how to fix this error or any workaround? As you can see in the code above, I tried specifying the classloader (I read it in some other thread on these forums), but no luck there.
    Or is this a known problem in 1.5.0_22? Can anyone else replicate it?

    Installation howto you can find on http://www.puschitz.com
    Try use "Search" function before you create new topic. This one was discussed many times.

  • Characters show up as boxes when using AWT components.

    Having installed on a Windows XP english OS the asian languages packs (with fonts included, from Microsoft) and knowing that with MS Gothic, Gulim and Simsun you can display japanese, korean and chinese characters it seems that on JRE 1.5 and up this is not possible (boxes appear instead) on any applet.
    How to reproduce:
    Label l2 = new Label("Japanese chars: \u8457\u4f5c\u6a29");
    Workaround:
    Step 1. Rename ..\jre\lib\fontconfig.properties.src to &hellip;&hellip;\fontconfig.properties
    Step 2. Modify the following line:
    sequence.allfonts=alphabetic/default,dingbats,symbol
    to
    sequence.allfonts=alphabetic/default,dingbats,symbol,japanese,chinese-ms936,chinese-ms950,korean
    How is this possible? On JRE 1.4 this was working. Also another fix is to use Swing components instead but this is not realistic for a big project.
    Any help will be greatly apprecied.

    The problem is related to the JRE v. 1.5.0_11 or greater. In JRE 1.4.2_13 for each language there was a configuration file that Java was using to determine which fonts to use for different categories of objects.
    The problem is encountered only for AWT components.
    Starting with JRE 1.5 (http://java.sun.com/j2se/1.5.0/docs/guide/intl/fontconfig.html) there is only one configuration file (fontconfig.properties.src) for all the languages. Since the character subsets supported by given fonts often overlap, in the file separate search sequence properties are used to define in which order to try the fonts when rendering a character. In the default version of the file this properties do not specify also the asian languages.
    We have to do the following things:
    *1.* You must first install into Windows the support for asian languages: Control Panel - > Regional and Language Options
    � On the Advanced tab add the conversion tables for all Asian languages (this action may not be required).
    � On the Languages tab check �Install files for East Asian Languages (this action is required)
    Restart the computer.
    *2.* Assure you have the needed asian fonts : batang(fopr korean), simsun, gulim, mingliu, msgothic(for japanese) installed.
    *3.* Rename ...\jre\lib\fontconfig.properties.src to ��\jre\lib\fontconfig.properties. By doing this the fontconfig.properties file will be used by the JRE as the default configuration file.
    *4.* Modify the following line:
    sequence.allfonts=alphabetic/default,dingbats,symbol
    to
    sequence.allfonts=alphabetic/default,dingbats,symbol,japanese,chinese-ms936,chinese-ms950,korean
    *5.* Assure that in the file the logical to physic font binding, binds to existing fonts.
    Obs: If step 1 is skipped the titles of the windows will still have boxes.
    Hope it helps.
    Donoiu Cristian

  • Swing components and Mac OS/9

    Hi all,
    I 've developped an app using swing components (Simple app using a hsqlbd database) and i read that it was kind of possible to port it on a mac os/9.
    I had a look on the net, on the apple site, without any luck as how to "add" swing library on the mac os/9.
    If someone could point me to the right direction (Web site, book etc), I 've been looking for a while without finding any clear and precise info on how to tackle this kind of problem.
    Thanks in advance.

    As per my knowledge, u can use JJEdit editor on MAC OS X. By using this editor, you can run the applets. Here I am using JJEdit as a java editor on MAC OS X. just dowload the JJEdit. and run the applet on it.
    regards
    nr konjeti

Maybe you are looking for