Various questions (GridBagLayout, Showing Panel, Paste)

Hi everybody,
I'm quite new to GUI and swing programming and I'm having some problems. I'm trying to use a GridBagLoyaout, to add Components I use the following method:
protected void add(Component c, int posx, int posy, int lenx, int leny, int weightx, int weighty){
     GridBagConstraints constraints = new GridBagConstraints();
     constraints.gridx = posx;
     constraints.gridy = posy;
     constraints.gridwidth = lenx;
     constraints.gridheight = leny;
     constraints.weightx = weightx;
     constraints.weighty = weighty;
     constraints.fill = GridBagConstraints.NONE;
     constraints.anchor = GridBagConstraints.WEST;
     add(c, constraints);
}this method is in an abstract class which extends JPanel and which is extended by all of my panels.
About that I have to say that there is a panel which contains other panel, in this way:
     JTextField name = new JTextField(40);
     JTextField surname = new JTextField(40);
     JTextArea notes = new JTextArea(4, 50);
     JPanel address = new AddressPane();
     JPanel[] phones = {new PhonePane(), new PhonePane(), new PhonePane(), new PhonePane()};
     JButton add = new JButton("Aggiungi");
     JButton cancel = new JButton("Annulla");
     JButton delete = new JButton("Cancella");
     JButton search = new JButton("Cerca");
     JButton edit = new JButton("Modifica");
     JButton remove = new JButton("Elimina");I add the declared component to the "main panel" using tese methods, which call the previous described add method
private void addMandatoryButtons(){
     add(delete, 2, 4+phones.length, 1, 1, 0, 0);
     add(cancel, 3, 4+phones.length, 1, 1, 0, 0);
private void addPanes(){
     add(address, 0, 2, 4, 1, 0, 0);
     address.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Indirizzo"));
     for(int i=0;i<phones.length;i++){
          add(phones, 0, 3+i, 4, 1, 0, 0);
          phones[i].setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Telefono " + String.valueOf(i+1)));
protected void addTextFields(){
     add(surname, 1, 0, 3, 1, 40, 0);
     add(name, 1, 1, 3, 1, 40, 0);
private void addTextAreasWithBorders(){
     JPanel notesPanel = new JPanel();
     notesPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Note"));
     notesPanel.add(notes);
     notes.setLineWrap(true);
     add(notesPanel, 0, 3+phones.length, 4, 1, 0, 0);
In the AddressPane and Phone Frame I add the components, in the same way, using these methods:
protected void addTextFields(){
     add(street, 1, 0, 3, 1, 30, 0);
     add(number, 5, 0, 1, 1, 5, 0);
     add(zip, 1, 1, 1, 1, 7, 0);
     add(town, 3, 1, 1, 1, 20, 0);
     add(country, 1, 2, 5, 1, 30, 0);
private void addCombo(){
     Province[] lista = AddressBookManager.current().getAllProvinces();
     province.setEditable(true);
     for(int i=0; i < lista.length; i++)
          province.addItem(lista.getCode());
     add(province, 5, 1, 1, 1, 2, 0);
protected void addTextFields(){
     add(prefix, 1, 0, 1, 1, 8, 0);
     add(number, 3, 0, 1, 1, 15, 0);
     add(note, 5, 0, 1, 1, 50, 0);
private void addCheckBox(){
     add(cellulare, 6, 0, 1, 1, 0, 0);
And the result being is really bad...
Apart the labels the other components are bad sized, if the window is not enlarged at the maximum the JTextFields are as short as they cannot be seen; being the window enlarged the pane is not shown as rectangle, but it's a kind of polygon made of different rectangles one on another.
What is my fault? What do I miss?
Then I have another question: I have a kind of desktop and in order to open a "window" I call this method
public void openWindow(JPanel panel){
     this.panel = panel;
     getContentPane().add(panel, BorderLayout.CENTER);
     repaint();
}But why I don't see the newly added panel until I resize the desktop window??
Last but not least question, I'm trying to implement a paste emthod, but how do I know where I have to paste having more than one JTextComponent? How do I get to know where is the caret?
I tried with the methods isFocusOwner(), getCaret()!=null and getCaretPosition()>=0.
I hope to get answerd to all of my questions soon, thanks a lot in advance.
Best regards.
Giorgio

Help me...
Hi everybody,
I'm quite new to GUI and swing programming and I'm
having some problems. I'm trying to use a
GridBagLoyaout, to add Components I use the following
method:
protected void add(Component c, int posx, int posy,
int lenx, int leny, int weightx, int weighty){
GridBagConstraints constraints = new
GridBagConstraints();
     constraints.gridx = posx;
     constraints.gridy = posy;
     constraints.gridwidth = lenx;
     constraints.gridheight = leny;
     constraints.weightx = weightx;
     constraints.weighty = weighty;
     constraints.fill = GridBagConstraints.NONE;
     constraints.anchor = GridBagConstraints.WEST;
     add(c, constraints);
}this method is in an abstract class which extends
JPanel and which is extended by all of my panels.
About that I have to say that there is a panel which
contains other panel, in this way:
     JTextField name = new JTextField(40);
     JTextField surname = new JTextField(40);
     JTextArea notes = new JTextArea(4, 50);
     JPanel address = new AddressPane();
JPanel[] phones = {new PhonePane(), new PhonePane(),
new PhonePane(), new PhonePane()};
     JButton add = new JButton("Aggiungi");
     JButton cancel = new JButton("Annulla");
     JButton delete = new JButton("Cancella");
     JButton search = new JButton("Cerca");
     JButton edit = new JButton("Modifica");
     JButton remove = new JButton("Elimina");I add the declared component to the "main panel" using
tese methods, which call the previous described add
method
private void addMandatoryButtons(){
     add(delete, 2, 4+phones.length, 1, 1, 0, 0);
     add(cancel, 3, 4+phones.length, 1, 1, 0, 0);
private void addPanes(){
     add(address, 0, 2, 4, 1, 0, 0);
     address.setBorder(BorderFactory.createTitledBorder(Bor
erFactory.createEtchedBorder(), "Indirizzo"));
     for(int i=0;i<phones.length;i++){
          add(phones, 0, 3+i, 4, 1, 0, 0);
          phones[i].setBorder(BorderFactory.createTitledBorder(
orderFactory.createEtchedBorder(), "Telefono " +
String.valueOf(i+1)));
protected void addTextFields(){
     add(surname, 1, 0, 3, 1, 40, 0);
     add(name, 1, 1, 3, 1, 40, 0);
private void addTextAreasWithBorders(){
     JPanel notesPanel = new JPanel();
     notesPanel.setBorder(BorderFactory.createTitledBorder(
orderFactory.createEtchedBorder(), "Note"));
     notesPanel.add(notes);
     notes.setLineWrap(true);
     add(notesPanel, 0, 3+phones.length, 4, 1, 0, 0);
In the AddressPane and Phone Frame I add the
components, in the same way, using these methods:
protected void addTextFields(){
     add(street, 1, 0, 3, 1, 30, 0);
     add(number, 5, 0, 1, 1, 5, 0);
     add(zip, 1, 1, 1, 1, 7, 0);
     add(town, 3, 1, 1, 1, 20, 0);
     add(country, 1, 2, 5, 1, 30, 0);
private void addCombo(){
Province[] lista =
AddressBookManager.current().getAllProvinces();
     province.setEditable(true);
     for(int i=0; i < lista.length; i++)
          province.addItem(lista.getCode());
     add(province, 5, 1, 1, 1, 2, 0);
protected void addTextFields(){
     add(prefix, 1, 0, 1, 1, 8, 0);
     add(number, 3, 0, 1, 1, 15, 0);
     add(note, 5, 0, 1, 1, 50, 0);
private void addCheckBox(){
     add(cellulare, 6, 0, 1, 1, 0, 0);
And the result being is really bad...
Apart the labels the other components are bad sized,
if the window is not enlarged at the maximum the
JTextFields are as short as they cannot be seen; being
the window enlarged the pane is not shown as
rectangle, but it's a kind of polygon made of
different rectangles one on another.
What is my fault? What do I miss?
Then I have another question: I have a kind of desktop
and in order to open a "window" I call this method
public void openWindow(JPanel panel){
     this.panel = panel;
     getContentPane().add(panel, BorderLayout.CENTER);
     repaint();
}But why I don't see the newly added panel until I
resize the desktop window??
Last but not least question, I'm trying to implement a
paste emthod, but how do I know where I have to paste
having more than one JTextComponent? How do I get to
know where is the caret?
I tried with the methods isFocusOwner(),
getCaret()!=null and getCaretPosition()>=0.
I hope to get answerd to all of my questions soon,
thanks a lot in advance.
Best regards.
Giorgio

Similar Messages

  • HT5787 Help, I have forgotten my Apple ID security questions and when i send it to my email address to reset the questions nothing shows up in inbox. Any other way to get past this?

    Help, I have forgotten my Apple ID security questions and when i send it to my email address to reset the questions nothing shows up in inbox. Any other way to get past this?

    You've checked the spam folder on your rescue email account as well as the inbox, and you've tried clicking the reset link a second time ? If you have, and you still haven't received the email, then you will need to contact iTunes Support / Apple to get the questions reset.
    Contacting Apple about account security : http://support.apple.com/kb/HT5699

  • Help, I have forgotten my Apple ID security questions and when i send it to my email address to reset the questions nothing shows up in inbox. Any other way to get past this?

    Help, I have forgotten my Apple ID security questions and when i send it to my email address to reset the questions nothing shows up in inbox. Any other way to get past this?

    Security questions:
    https://discussions.apple.com/docs/DOC-4551
    http://support.apple.com/kb/HT5312
    This is also useful:
    http://www.macworld.co.uk/ipad-iphone/news/?newsid=3463233&olo=email
    If you don’t know your security questions, phone Apple (using the number listed here:  http://support.apple.com/kb/HE57  ) and ask for the Account Security Team.

  • Recently PopClip stopped showing "Cut," "Paste," and other similar options

    Hello,
    Recently, PopClip stopped showing "Cut," "Paste," and other similar options. I haven't changed anything in the settings. Maybe this will help:
    2013-06-04 18:55:22.886 PopClip[1167:707] [INFO] PopAppDelegate: PopClip Initializing.
    2013-06-04 18:55:23.089 PopClip[1167:707] Could not find image named 'BuyLabel'.
    2013-06-04 18:55:23.093 PopClip[1167:707] Could not find image named 'BlueTick'.
    2013-06-04 18:55:23.162 PopClip[1167:707] NSWindow does not support nonactivating panel styleMask 0x80
    2013-06-04 18:55:23.164 PopClip[1167:707] [INFO] PopAppDelegate: PopClip will wait 0.500000 seconds to start.
    2013-06-04 18:55:26.591 PopClip[1167:707] .sdef warning for argument 'FileType' of command 'save' in suite 'Standard Suite': 'saveable file format' is not a valid type name.
    2013-06-04 18:55:26.623 PopClip[1167:707] Bartender Loaded
    logout
    Thank you in advance for the help!

    This is something you'll want to address with the developer of PopClip.

  • I have a question. For the past week I have not been able to access my iTunes app it always kicks me out. I've turned it off and on and still nothing. I was wondering how can I get it to work or what should I do. Thank you

    I have a question. For the past week I have not been able to access my iTunes app it always kicks me out. I've turned it off and on and still nothing. I was wondering how can I get it to work or what should I do. Thank you

    You need a computer with iTunes and an internet connection
    Try:
    - Restore from backup. See:                                               
    iOS: Back up and restore your iOS device with iCloud or iTunes
    - Restore to factory settings/new iOS device.                       
    If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
      Apple Retail Store - Genius Bar                                                              

  • How do I get the Questions to show in the 'View Responses' TAB, and then show up in the Summary Report?

    How do I get the Questions to show in the 'View Responses' TAB, and then show up in the Summary Report?

    There are more than one Applications folders. At the root level of your system is an Applications folder for all users, where most installations go. Every user, including you, also has a separat Applications folder.
    Check all of them.

  • Last month I was 1 day late paying my bill, so I tried to pay the full amount.  But the website would only allow me to pay the current bill amount.  Now, I show a past due amount.  If I tried paying it and Verizon didn't allow me, how is it past due?

    Last month I was 1 day late paying my bill, so I tried to pay the full amount.  But the website would only allow me to pay the current bill amount.  Now, I show a past due amount.  If I tried paying it and Verizon didn't allow me, how is it past due?

    I'm confused - If I go online to pay my bill, and it's one day after the due date, the current bill and full amount due would be the same?  If the current bill is not the "full amount due", then what is the extra amount that's snow showing past due?
    Also, when I go in to pay my bill, I show the Current bill amount, total amount due (which are the same), and then a box where I can type in the amount I am paying, with the default amount being already filled in with the total amount. 
    Is this a pre-paid or a post-paid (contract) account?

  • Missing "Hide Panels/Show Panels" in Windows menu

    Attempting to change a setting in a Spry menu bar, I discovered that I am missing the "Hide Panels/Show Panels" choice in the windows menu, rendering the Spry menu bar contents now unavailable for change. (The "Hide Panels" text now shows up as faint lettering in contrast to all the other choices).
    This function is necessary to make changes in a Spry menu bar. How can I restore this function?
    Professor Bob

    Try resetting your view.
    Brad Lawryk
    Community Expert: Dreamweaver
    Usergroup Manager: Northern British Columbia Adobe Usersgroup

  • ICal is not showing some past events since I upgraded to Lion.

    iCal is not showing some past events since I upgraded to Lion. I can find the past events in mail but if I click and open them, they are not showing up on the calendar. Advice? I am trying to recreate my schedule from past meetings.

    I love computers.
    Have managed to fix this already. Been working the issue for a few days now, and a few minutes after writing the above post I decided to reset the Time Capsule to factory default settings.
    After entering all my details again (used same network names, passwords etc) the Time Capsule was rebooted. When it came back on line - guess what? Yep, the MyBook WD drive is now visibile. I can connect via the network from my other machines to the drive, and iTunes is back.
    So - thought I would post my resolution in case it helps others.

  • A few various questions

    Can anyone help me with a few various questions about how to do certain things on the iPhone? Here's my questions:
    - Is there a way to turn off predictive text? I'd like to enter in a phone extension for a contact. I create a new field for the extension number. Then enter in "EXT" but it comes out to "ECT". Also, is there a way to delete that field? Is there a better way to do extensions?
    - How do I hide the keyboard when there isn't an option to hide it? This happens in the Mail settings area.
    - Is there a way to keep the keyboard in all caps just for a single word rather than having to switch to caps for each letter?
    - When I bookmark a website, sometimes the bookmark title is long so I can't see it all. I can click into the field but that puts the cursor at the end of the text string. Is there a way to then scroll left and see all of the words?
    Thanks,
    Brett

    Ok this should be a long one so dig in haha. Ill answer them in the order you asked.
    No, there is no way as of right now to turn off the predictive text feature. You must make sure to cancel the blue suggested word before hitting the space bar.
    There isnt an option to hide the keyboard in any of the applications on iPhone. Im not quite sure what you mean on this one either.
    There is a way to use all caps letters if you have enabled caps lock in the keyboard settings menu and then double tap the icon when typing. It will turn blue when it has been done correctly.
    If you tap and hold your finger on a piece of text, it will pop up a little magnifying glass which can be used to scroll left and right. Its a bit tricky to find the right place on the screen that will make it move though. You will get the hang of it eventually.
    Hope this helps. Enjoy your iPhone!!

  • Basic question: showing panel group

    Hello,
    I am new to Fireworks CS4. I have right-claicked on the panel group that displays the
    OPTIMIZE, HISTORY, and ALIGN tabs. Now I want to open it up again but cannot
    find the way how to do it.
    In Flash there is a way to reset the entire workspace to its default but I cannot
    find such an option in fireworks.
    Any ideas on how i should proceed?
    Thanks,
    John Goche

    Hello,
    I am running Windows 7 64-bit with Fireoworks CS4.
    According to the book Adobe Fireworks CS4 How-Tos: 100 Essential Techniques
    a user should be able to save the current workspace via:
    Window > Workspace Layouts > Save Current
    However my Window menu does not display a Workspace Layouts item.
    Am I looking in the wrong place? Anyone else have this issue?
    John Goche

  • GridBagLayout and Panel Border problem

    I have 3 panels like
    A
    B
    C
    and the C panel has a Mouse Listener that on a mouseEntered creates a border around the same panel and on a mouseExited clears that border.
    When this border is created the A and B panels go up a little bit .. they move alone when the border is created.
    Is there any way to fix this problem? Is there any way to get the panels static?
    the code is close to the following:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseEvent;
    import javax.swing.BorderFactory;
    import javax.swing.border.Border;
    import javax.swing.border.TitledBorder;
    import java.awt.event.*;
    import java.text.NumberFormat;
    public class Game extends JFrame implements MouseListener
    JPanel game, options, top, down, middle;
    NumberFormat nf;
    public Game() {
    super("Game");
    nf = NumberFormat.getPercentInstance();
    nf.setMaximumFractionDigits(1);
    JPanel center = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = gbc.BOTH;
    gbc.weighty = 1.0;
    gbc.weightx = 0.8;
    center.add(getGamePanel(), gbc);
    gbc.weightx = 0.104;
    center.add(getOptionsPanel(), gbc);
    Container cp = getContentPane();
    // use the JFrame default BorderLayout
    cp.add(center); // default center section
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setSize(700,600);
    // this.setResizable(false);
    setLocationRelativeTo(null);
    setVisible(true);
    addComponentListener(new ComponentAdapter()
    public void componentResized(ComponentEvent e)
    showSizeInfo();
    showSizeInfo();
    private void showSizeInfo()
    Dimension d = getContentPane().getSize();
    double totalWidth = game.getWidth() + options.getWidth();
    double gamePercent = game.getWidth() / totalWidth;
    double optionsPercent = options.getWidth() / totalWidth;
    double totalHeight = top.getHeight() + middle.getHeight() + down.getHeight();
    double topPercent = top.getHeight() / totalHeight;
    double middlePercent = middle.getHeight() / totalHeight;
    double downPercent = down.getHeight() / totalHeight;
    System.out.println("content size = " + d.width + ", " + d.height + "\n" +
    "game width = " + nf.format(gamePercent) + "\n" +
    "options width = " + nf.format(optionsPercent) + "\n" +
    "top height = " + nf.format(topPercent) + "\n" +
    "middle height = " + nf.format(middlePercent) + "\n" +
    "down height = " + nf.format(downPercent) + "\n");
    private JPanel getGamePanel()
    // init components
    top = new JPanel(new BorderLayout());
    top.setBackground(Color.red);
    top.add(new JLabel("top panel", JLabel.CENTER));
    middle = new JPanel(new BorderLayout());
    middle.setBackground(Color.green.darker());
    middle.add(new JLabel("middle panel", JLabel.CENTER));
    down = new JPanel(new BorderLayout());
    down.setBackground(Color.blue);
    down.add(new JLabel("down panel", JLabel.CENTER));
    // layout game panel
    game = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.weightx = 1.0;
    gbc.fill = gbc.BOTH;
    gbc.gridwidth = gbc.REMAINDER;
    gbc.weighty = 0.2;
    game.add(top, gbc);
    gbc.weighty = 0.425;
    game.add(middle, gbc);
    gbc.weighty = 0.2;
    game.add(down, gbc);
    down.addMouseListener(this);
    return game;
    private JPanel getOptionsPanel()
    options = new JPanel(new BorderLayout());
    options.setBackground(Color.pink);
    options.add(new JLabel("options panel", JLabel.CENTER));
    return options;
    // mouse listener events
         public void mouseClicked( MouseEvent e ) {
    System.out.println("pressed");
         public void mousePressed( MouseEvent e ) {
         public void mouseReleased( MouseEvent e ) {
         public void mouseEntered( MouseEvent e ) {
    Border redline = BorderFactory.createLineBorder(Color.red);
    JPanel x = (JPanel) e.getSource();
    x.setBorder(redline);
         public void mouseExited( MouseEvent e ){
    JPanel x = (JPanel) e.getSource();
    x.setBorder(null);
    public static void main(String[] args ) {
    Game exe = new Game();
    exe.show();
    }

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.event.*;
    import java.text.NumberFormat;
    public class Game extends JFrame implements MouseListener{
      JPanel game, options, top, down, middle;
      NumberFormat nf;
      public Game() {
        super("Game");
        nf = NumberFormat.getPercentInstance();
        nf.setMaximumFractionDigits(1);
        JPanel center = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.fill = gbc.BOTH;
        gbc.weighty = 1.0;
        gbc.weightx = 0.8;
        center.add(getGamePanel(), gbc);
        gbc.weightx = 0.104;
        center.add(getOptionsPanel(), gbc);
        Container cp = getContentPane();
        // use the JFrame default BorderLayout
        cp.add(center); // default center section
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setSize(700,600);
        // this.setResizable(false);
        setLocationRelativeTo(null);
        setVisible(true);
        addComponentListener(new ComponentAdapter(){
            public void componentResized(ComponentEvent e){
            showSizeInfo();
        showSizeInfo();
      private void showSizeInfo(){
        Dimension d = getContentPane().getSize();
        double totalWidth = game.getWidth() + options.getWidth();
        double gamePercent = game.getWidth() / totalWidth;
        double optionsPercent = options.getWidth() / totalWidth;
        double totalHeight = top.getHeight() + middle.getHeight() + down.getHeight();
        double topPercent = top.getHeight() / totalHeight;
        double middlePercent = middle.getHeight() / totalHeight;
        double downPercent = down.getHeight() / totalHeight;
        System.out.println("content size = " + d.width + ", " + d.height + "\n" +
            "game width = " + nf.format(gamePercent) + "\n" +
            "options width = " + nf.format(optionsPercent) + "\n" +
            "top height = " + nf.format(topPercent) + "\n" +
            "middle height = " + nf.format(middlePercent) + "\n" +
            "down height = " + nf.format(downPercent) + "\n");
      private JPanel getGamePanel(){
        // init components
        top = new JPanel(new BorderLayout());
        top.setBackground(Color.red);
        top.add(new JLabel("top panel", JLabel.CENTER));
        middle = new JPanel(new BorderLayout());
        middle.setBackground(Color.green.darker());
        middle.add(new JLabel("middle panel", JLabel.CENTER));
        down = new JPanel(new BorderLayout());
        down.setBackground(Color.blue);
        down.add(new JLabel("down panel", JLabel.CENTER));
        // layout game panel
        game = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.weightx = 1.0;
        gbc.fill = gbc.BOTH;
        gbc.gridwidth = gbc.REMAINDER;
        gbc.weighty = 0.2;
        game.add(top, gbc);
        gbc.weighty = 0.425;
        game.add(middle, gbc);
        gbc.weighty = 0.2;
        game.add(down, gbc);
        down.addMouseListener(this);
        return game;
      private JPanel getOptionsPanel(){
        options = new JPanel(new BorderLayout());
        options.setBackground(Color.pink);
        options.add(new JLabel("options panel", JLabel.CENTER));
        return options;
      public void mouseClicked( MouseEvent e ) {
        System.out.println("pressed");
      public void mousePressed( MouseEvent e ) {
      public void mouseReleased( MouseEvent e ) {
      public void mouseEntered( MouseEvent e ) {
        Border redline = new CalmLineBorder(Color.red);
        JPanel x = (JPanel) e.getSource();
        x.setBorder(redline);
      public void mouseExited( MouseEvent e ){
        JPanel x = (JPanel) e.getSource();
        x.setBorder(null);
      public static void main(String[] args ) {
        Game exe = new Game();
        exe.setVisible(true);
    class CalmLineBorder extends LineBorder{
      public CalmLineBorder(Color c){
        super(c);
      public CalmLineBorder(Color c, int thick){
        super(c, thick);
      public CalmLineBorder(Color c, int thick, boolean round){
        super(c, thick, round);
      public Insets getBorderInsets(Component comp){
        return new Insets(0, 0, 0, 0);
    }

  • GridBagLayout with Panels

    In a nutshell I have five panels. The comboPanel contains a label and comboBox; objectPanel has a label and text field; filePanel and directPanel have a label, text field and button; buttonPanel has two buttons.
    When the program is first run only the comboPanel is visible. If "Display object and filePanel" is selected from the comboBox then the objectPanel and filePanel are visible, else directPanel is visible. buttonPanel is visible no matter what is selected.
    The problem is I am trying to add them to the GridBayLayout and have them display below one another which is why I am using gbc.gridwidth = GridBagConstraints.REMAINDER for each, however they are all showing up on the same line.
    Thanks in advance
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class SMG3AuditInterface extends JFrame
        JComboBox comboBox;
        JLabel lblComponent, lblObjectName, lblFileName, lblDirectName;
        JTextField tfObjectName, tfFileName, tfDirectName;
        JButton btnSubmit, btnCancel, btnFileBrowse, btnDirectBrowse;
        JPanel comboPanel, objectPanel, filePanel, directPanel, buttonPanel;
        GridBagLayout gb;
        GridBagConstraints gbc;
        public SMG3AuditInterface()
        gb = new GridBagLayout();
        gbc = new GridBagConstraints();
        Container cp = getContentPane();
        cp.setLayout(gb);
        String components[] = {"Display directPanel",
            "Display object and filePanel"};
        comboBox = new JComboBox(components);
        comboBox.setSelectedIndex(-1);
        lblComponent = new JLabel("Component Type: ");
        comboPanel = new JPanel();
        comboPanel.add(lblComponent);
        comboPanel.add(comboBox);
        cp.add(comboPanel);
        lblObjectName = new JLabel("Object name: ");
        tfObjectName = new JTextField(20);
        objectPanel = new JPanel();
        objectPanel.add(lblObjectName);
        objectPanel.add(tfObjectName);
        cp.add(objectPanel);
        objectPanel.setVisible(false);
        lblFileName = new JLabel("XML Filename: ");
        tfFileName = new JTextField(20);
        btnFileBrowse = new JButton("Browse");
        filePanel = new JPanel();
        filePanel.add(lblFileName);
        filePanel.add(tfFileName);
        filePanel.add(btnFileBrowse);
        cp.add(filePanel);
        filePanel.setVisible(false);
        lblDirectName = new JLabel("XML Directory name: ");
        tfDirectName = new JTextField(20);
        btnDirectBrowse = new JButton("Browse");
        directPanel = new JPanel();
        directPanel.add(lblDirectName);
        directPanel.add(tfDirectName);
        directPanel.add(btnDirectBrowse);
        cp.add(directPanel);
        directPanel.setVisible(false);
        btnSubmit = new JButton("Submit");
        btnCancel = new JButton("Cancel");
        buttonPanel = new JPanel();
        buttonPanel.add(btnSubmit);
        buttonPanel.add(btnCancel);
        cp.add(buttonPanel);
        buttonPanel.setVisible(false);
        gbc.gridx = GridBagConstraints.RELATIVE;
        gbc.gridy = GridBagConstraints.RELATIVE;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.ipadx = 0;
        gbc.ipady = 0;
        gbc.gridwidth = 3;
        gbc.gridheight = 1;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gb.setConstraints(comboPanel, gbc);
        add(comboPanel);
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.gridheight = 1;
        gb.setConstraints(objectPanel, gbc);
        add(objectPanel);
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.gridheight = 2;
        gb.setConstraints(filePanel, gbc);
        add(filePanel);
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.gridheight = 2;
        gb.setConstraints(directPanel, gbc);
        add(directPanel);
        gbc.gridwidth = 2;
        gbc.gridheight = 1;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gb.setConstraints(buttonPanel, gbc);
        add(buttonPanel);
        comboBox.addItemListener(new ItemListener()
           public void itemStateChanged(ItemEvent e)
              JComboBox cb = (JComboBox)e.getSource();
              String itemName = (String)cb.getSelectedItem();
              buttonPanel.setVisible(true);
              if (itemName == "Display object and filePanel")
                 objectPanel.setVisible(true);
                 filePanel.setVisible(true);
                 directPanel.setVisible(false);
              else
                 objectPanel.setVisible(false);
                 filePanel.setVisible(false);
                 directPanel.setVisible(true);
        public static void main(String[] args)
        SMG3AuditInterface ai = new SMG3AuditInterface();
        ai.setDefaultCloseOperation(ai.EXIT_ON_CLOSE);
        ai.setLocation(400, 300);
        ai.setPreferredSize(new Dimension(400,300));
        ai.pack();
        ai.show();
    }

    Here's an example:
    import java.awt.BorderLayout;
    import java.awt.CardLayout;
    import java.awt.FlowLayout;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.GridLayout;
    import java.awt.Insets;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    public class SMG3Petes extends JPanel
        private static final String DIRECT_PANEL = "Display directPanel";
        private static final String OBJECT_FILE_PANEL = "Display object and filePanel";
        private static final String components[] =
            DIRECT_PANEL, OBJECT_FILE_PANEL
        private static final String SUBMIT = "Submit";
        private static final String CANCEL = "Cancel";
        private static final String EMPTY_PANEL = "Empty Panel";
        private JPanel centerPanel;
        private CardLayout cardlayout = new CardLayout();
        private JComboBox comboBox;
        private JButton submitBtn = new JButton(SUBMIT);
        private JButton cancelBtn = new JButton(CANCEL);
        private JTextField tfObjectName = new JTextField(20);
        private JTextField tfFileName = new JTextField(20);
        private JTextField tfDirectName = new JTextField(20);
        public SMG3Petes()
            int eb = 15;
            setBorder(BorderFactory.createEmptyBorder(eb, eb, eb, eb));
            setLayout(new BorderLayout());
            add(createBigCenterPanel(), BorderLayout.CENTER);
            add(createPageEndPanel(), BorderLayout.PAGE_END);
        private JPanel createBigCenterPanel()
            JPanel p = new JPanel();
            p.setLayout(cardlayout);
            p.add(new JPanel(), EMPTY_PANEL);
            p.add(createObjectFilePanel(), OBJECT_FILE_PANEL);
            p.add(createDirectPanel(), DIRECT_PANEL);
            centerPanel = p;
            return p;
        private JPanel createObjectFilePanel()
            JPanel p = new JPanel();
            p.setLayout(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.gridx = 0;
            gbc.gridy = 0;
            gbc.gridheight = 1;
            gbc.gridwidth = 1;
            gbc.weightx = 1;
            gbc.weighty = 1;
            gbc.insets = new Insets(5, 5, 5, 5);
            p.add(new JLabel("Object name: "), gbc);
            gbc.gridx = 1;
            gbc.gridwidth = 2;
            gbc.weightx = 2;
            p.add(tfObjectName, gbc);
            gbc.gridx = 3;
            gbc.gridwidth = 1;
            gbc.weightx = 1;
            p.add(new JLabel("   "));
            gbc.gridx = 0;
            gbc.gridy = 1;
            gbc.gridwidth = 1;
            gbc.weightx = 1;
            p.add(new JLabel("XML Filename: "), gbc);
            gbc.gridx = 1;
            gbc.gridwidth = 2;
            gbc.weightx = 2;
            p.add(tfFileName, gbc);
            gbc.gridx = 3;
            gbc.gridwidth = 1;
            gbc.weightx = 1;
            JButton browseBtn = new JButton("Browse");
            p.add(browseBtn, gbc);
            return p;
        private JPanel createDirectPanel()
            JPanel p = new JPanel(new FlowLayout(FlowLayout.CENTER, 25, 0));
            JLabel lblDirectName = new JLabel("XML Directory name: ");
            tfDirectName = new JTextField(20);
            JButton btnDirectBrowse = new JButton("Browse");
            p.add(lblDirectName);
            p.add(tfDirectName);
            p.add(btnDirectBrowse);
            return p;
        private JPanel createPageEndPanel()
            JPanel p = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 0));
            p.add(createComboPanel());
            p.add(createButtonPanel());
            return p;
        private JPanel createComboPanel()
            comboBox = new JComboBox(components);
            comboBox.setSelectedIndex(-1);
            comboBox.addItemListener(new ComboItemListener());
            JPanel p = new JPanel();
            p.add(new JLabel("Component Type: "));
            p.add(comboBox);
            return p;
        private class ComboItemListener implements ItemListener
            public void itemStateChanged(ItemEvent ie)
                submitBtn.setEnabled(true);
                cancelBtn.setEnabled(true);
                String itemName = (String) comboBox.getSelectedItem();
                if (itemName.equals(DIRECT_PANEL))
                    cardlayout.show(centerPanel, DIRECT_PANEL);
                else if (itemName.equals(OBJECT_FILE_PANEL))
                    cardlayout.show(centerPanel, OBJECT_FILE_PANEL);
        private JPanel createButtonPanel()
            JPanel p = new JPanel(new GridLayout(1, 0, 15, 0));
            submitBtn.setEnabled(false);
            cancelBtn.setEnabled(false);
            p.add(submitBtn);
            p.add(cancelBtn);
            return p;
        private static void createAndShowGUI()
            JFrame frame = new JFrame("SMG3 Petes1234 Application");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(new SMG3Petes());
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public static void main(String[] args)
            javax.swing.SwingUtilities.invokeLater(new Runnable()
                public void run()
                    createAndShowGUI();
    }

  • Question about showing jpeg metadata in lightroom

    Hi,
    I have briefly gone through the sdk material but there are some aspects that remained unclear to me. In more detail, I would like to show the RegionName tag from jpg-file in the LR metadata for searching etc. This tag includes the face recognition data from Picasa. I have already experimented with the exiftool and know how to add the names in RegionName to Subject or Keywords tag in both jpg-file and corresponding .xmp file for the raw-file. However, I would like to find an elegant solution by showing the tag in the LR directly. Before trying the make the LUA code, I would like to understand some basic principles behind the plugin programming namely:
    1) How do I read the RegionName tag from the jpg-file and in which part of the plug-in? Is there a way to make LR read it every time the "Read Metadata from File" is used?
    2) How do I "publish" it to appear in the Metadata panel on the right side of the LR (this is somewhat handled in the examples even though I do not understand the com.adobe.xxx reference i.e. which structure is it actually referencing to?)
    Any comments and help is welcome on this or any advice where to find the information!
    Mikko

    Mikko,
    LR provides access only to some metadata fields, not all.  RegionName is not one of the fields LR knows about, so you won't be able to use the SDK's metadata methods to access or display it.  Typically, plugins that want to access such metadata run the free Exiftool on the images and then parse the output of Exiftool. 
    The ExifMeta plugin exposes all metadata that's accessible by Exiftool as custom metadata fields in LR.  I suggest you try out that plugin to see if it meets your needs.  If it doesn't, you can examine its source code as an example of how to use Exiftool to access and display metadata.  The plugin's author Rob Cole is a frequent contributor to this forum and quite willing to answer questions.

  • Outputting to BetaSP - Various Questions

    Hi, I have a 10 minute segment of various clips that I plan to send out to various local/national broadcast companies. Since the universal broadcast format seems to be betasp, I am outputting to it.
    My first question is how much bar/tone do I need at the beginning and end of each tape?
    Secondly, as I am only equipped with DV firewire decks and a canopus ADVC300, would it be possible to output to miniDV tape and then from miniDV to BetaSP (by hooking up my miniDV deck to my betaSP deck). The video is standard NTSC.
    Any help would be appreciated. I hope I am supplying enough information.
    -Alexi

    My first question is how much bar/tone do I need at the beginning and end of each tape?
    1 min. Starting from 58:30:00 to 59:30:00. Program to start at 1:00:00:00 on the nose.
    Secondly, as I am only equipped with DV firewire decks and a canopus ADVC300, would it be possible to output to miniDV tape and then from miniDV to BetaSP (by hooking up my miniDV deck to my betaSP deck). The video is standard NTSC.
    Not if you want to deliver a show with the proper timecode. Either get a capture card, or have the dub done at a dub facility that can dub with the proper timecode...assuming you have the proper timing in the output.
    And you'd better make sure that the show is properly color corrected so that your whites don't exceed 100 IRE and your blacks don't go below 7.5 IRE...and that your colors are all within acceptable limits. And that your audio peaks a the proper levels.
    Shane

Maybe you are looking for

  • Pop-up LOV - Internal Server Error

    I have a pop-up LOV with the query as below: select distinct a1 d, a1 r from temp where ((:P10111_X1 = 2 or :P10111 is null) or (:P10111_X1 = 1 and (col1 like :P10111_col1 or :P10111_col1 is null) and (col2 like :P10111_col2 or :P10111_col2 is null)

  • How can i remove all my devices added to my Apple ID?

    How can i reset the added devices to my Apple ID, dearthursize all of my devices connected to my Apple ID? without having access to the devices, i think its my old computers that i dont have anymore. Just got a new computer, and i authersize it, beca

  • Login via Press Ctrl-Alt-Delete to begin

    Hi, Seems to have locked myself out. Screen shows Press Ctrl-Alt-Delete to begin, on Windows 2000 Prof, but nothing happens when these keys are pressed. Help!??! Yusuf

  • Airport Base Station Agent in Windows 7 Hangs when mouting Time Capsule

    Hey all, can't figure this one out. The airport base station agent launches at start up and asks if I'd like to ignore or connect with password. When I choose connect with password the agent hangs, and either goes unresponsive or puts up a dialogue b

  • Invoice and a credit memo at the same time

    Hello everybody, I have a question about the MIRO transaction; there is a provider that give us a monthly invoice where he put all the articles we have ordered, but ALSO those that we have returned the month before with a negative amount, instead of