Search Results

Search found 16 results on 1 pages for 'jtoolbar'.

Page 1/1 | 1 

  • BorderLayout problem with JSplitPane after adding JToolbar (Java)

    - by Alex Cheng
    Hello all. Problem: My program layout is fine, as below before I add JToolbar to BorderLayout.PAGE_START Here's a screenshot before JToolbar is added: Here's how it looked like after adding JToolbar: May I know what did I do wrong? Here's the code I used: //Create the text pane and configure it. textPane = new JTextPane(); -snipped code- JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(300, 300)); //Create the text area for the status log and configure it. changeLog = new JTextArea(5, 30); changeLog.setEditable(false); JScrollPane scrollPaneForLog = new JScrollPane(changeLog); //Create a split pane for the change log and the text area. JSplitPane splitPane = new JSplitPane( JSplitPane.VERTICAL_SPLIT, scrollPane, scrollPaneForLog); splitPane.setOneTouchExpandable(true); //Create the status area. JPanel statusPane = new JPanel(new GridLayout(1, 1)); CaretListenerLabel caretListenerLabel = new CaretListenerLabel("Caret Status"); statusPane.add(caretListenerLabel); //Create the toolbar JToolBar toolBar = new JToolBar(); -snipped code- //Add the components. getContentPane().add(toolBar, BorderLayout.PAGE_START); getContentPane().add(splitPane, BorderLayout.CENTER); getContentPane().add(statusPane, BorderLayout.PAGE_END); //Set up the menu bar. actions = createActionTable(textPane); JMenu editMenu = createEditMenu(); JMenu styleMenu = createStyleMenu(); JMenuBar mb = new JMenuBar(); mb.add(editMenu); mb.add(styleMenu); setJMenuBar(mb); Please help, I'm new to GUI Building, and I don't feel like using Netbeans to drag and drop the UI for me... Thank you in advance.

    Read the article

  • JToolbar is hidden by JMenu

    - by pierre
    I'm using Netbeans to add a JToolbar to my window which also has a JMenuBar. Here is the design-time look: .. but during run-time I get this: With the toolbar seemingly partially hidden under the menu names. This is on the Mac, btw. Is there something stupid I've forgotten to do or some layout trick I should be using? EDIT: I'll add that the area below the toolbar is a SplitContainer.

    Read the article

  • changing jtoolbar images when JMenuItem is clicked

    - by ammayi100
    Hi, I need to develop a swing application with a menubar. When a menu is clicked, I have to display the menu items as icons in one bar. Same like when another menu is selected, corresponding menu items should be displayed in the bar. How can I achieve this functionality using Swings? Any help would be appreciated. Thanks in Advance, Maruthi Prasanna.

    Read the article

  • Does anyone know how to layout a JToolBar that does't move or re-size any components placed in it?

    - by S1.Mac
    Can anyone help with this problem i'm trying to create a JToolBar and I want all its components to be fixed in size and position. I'v tried a few different layout managers but they all center and/or re-size the components when the frame its in is re-sized. here is an example using GridbagLayout, I have also used the default layout manager using the toolbar.add( component ) method but the result is the same : ' import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.*; public class ToolBarTest extends JFrame { private JToolBar toolbar; private JPanel mainPanel; private JPanel toolBarPanel; private JButton aButton; private JCheckBox aCheckBox; private JList aList; private Box toolbarBox; private GridBagConstraints toolbarConstraints; private GridBagLayout toolbarLayout; private JLabel shapeLabel; private JComboBox<ImageIcon> shapeChooser; private JLabel colorLabel; private JComboBox colorChooser; private String colorNames[] = { "Black" , "Blue", "Cyan", "Dark Gray", "Gray", "Green", "Light Gray", "Magenta", "Orange", "Pink", "Red", "White", "Yellow", "Custom" }; private String shapeNames[] = { "Line", "Oval", "Rectangle", "3D Rectangle","Paint Brush", "Rounded Rectangle" }; public ToolBarTest() { setLayout( new BorderLayout() ); setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); setSize( 500, 500 ); add( createToolBar(), BorderLayout.PAGE_START ); setVisible( true ); } public void addToToolbar( Component component, int row, int column ) { toolbarConstraints.gridx = column; toolbarConstraints.gridy = row; toolbarConstraints.anchor = GridBagConstraints.WEST; toolbarConstraints.fill = GridBagConstraints.NONE; toolbarConstraints.weightx = 0; toolbarConstraints.weighty = 0; toolbarConstraints.gridwidth = 1; toolbarConstraints.gridheight = 1; toolbarLayout.setConstraints( component, toolbarConstraints ); toolbar.add( component ); }// end addToToolbar public final JToolBar createToolBar() { toolbarLayout = new GridBagLayout(); toolbarConstraints = new GridBagConstraints(); // create the tool bar which holds the items to draw toolbar = new JToolBar(); toolbar.setBorderPainted(true); toolbar.setLayout( toolbarLayout ); toolbar.setFloatable( true ); shapeLabel = new JLabel( "Shapes: " ); addToToolbar( shapeLabel, 0, 1 ); String iconNames[] = { "PaintImages/Line.jpg", "PaintImages/Oval.jpg", "PaintImages/Rect.jpg", "PaintImages/3DRect.jpg","PaintImages/PaintBrush.jpg", "PaintImages/RoundRect.jpg"}; ImageIcon shapeIcons[] = new ImageIcon[ shapeNames.length ]; // create image icons for( int shapeButton = 0; shapeButton < shapeNames.length; shapeButton++ ) { shapeIcons[ shapeButton ] = new ImageIcon( iconNames[ shapeButton ] ); }// end for shapeChooser = new JComboBox< ImageIcon >( shapeIcons ); shapeChooser.setSize( new Dimension( 50, 20 )); shapeChooser.setPrototypeDisplayValue( shapeIcons[ 0 ] ); shapeChooser.setSelectedIndex( 0 ); addToToolbar( shapeChooser, 0, 2 ); colorLabel = new JLabel( "Colors: " ); addToToolbar( colorLabel, 0, 3 ); colorChooser = new JComboBox( colorNames ); addToToolbar( colorChooser, 0, 4 ); return toolbar; }// end createToolBar public static void main( String args[] ) { new ToolBarTest(); }// end main }// end class ToolBarTest'

    Read the article

  • How to make items fill available space in JToolBar?

    - by Konrad Garus
    I have a horizontal JToolbar with JToggleButtons. For some reason it is placed in a container that has larger height. My JToggleButtons use only as much space as they need, leaving ugly empty space below and under them. How can I make them fill all available space without setting size arbitrarily? Similar question: How I can make components fill all horizontal space in a vertical tool bar?

    Read the article

  • Java: Get Mainform object from JInternalFrame

    - by rodion
    Can I do this without reference to the object in the constructor? In other words, any class inherited from FrmTaoChild when creating must to add the button on the toolbar of the main window public class FrmTaoMain extends JFrame { JToolBar tbTask = new JToolBar(); public FrmTaoMain(String Caption) { super(Caption); ... FrmTaoChild FrmChild = new FrmTaoChild(tbTask,"test"); } } public class FrmTaoChild extends JInternalFrame { public FrmTaoChild(JToolBar tbTask, String Caption) { super (Caption); JButton btnTask = new JButton(Caption); tbTask.add(btnTask); } }

    Read the article

  • Loosely Coupled Tabs in Java Editor

    - by Geertjan
    One of the NetBeans Platform 7.1 API enhancements is the @MultiViewElement.Registration annotation. That lets you add a new tab to any existing NetBeans editor. Really powerful since I didn't need to change the sources (or even look at the sources) of the Java editor to add the "Visualizer" tab to it, as shown below: Right now, the tab doesn't show anything, that will come in the next blog entry. The point here is to show how to set things up so that you have a new tab in the Java editor, without needing to touch any of the NetBeans IDE sources: And here's the code, take note of the annotation, which registers the JPanel for the "text/x-java" MIME type: import javax.swing.Action; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.JToolBar; import org.netbeans.core.spi.multiview.CloseOperationState; import org.netbeans.core.spi.multiview.MultiViewElement; import org.netbeans.core.spi.multiview.MultiViewElementCallback; import org.openide.awt.UndoRedo; import org.openide.loaders.DataObject; import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.openide.windows.TopComponent; @MultiViewElement.Registration(displayName = "#LBL_Visualizer", iconBase = "org/java/vis/icon.gif", mimeType = "text/x-java", persistenceType = TopComponent.PERSISTENCE_NEVER, preferredID = "JavaVisualizer", position = 3000) @NbBundle.Messages({     "LBL_Visualizer=Visualizer" }) public class JavaVisualizer extends JPanel implements MultiViewElement {     private JToolBar toolbar = new JToolBar();     private DataObject obj;     private MultiViewElementCallback mvec;     public JavaVisualizer(Lookup lkp) {         obj = lkp.lookup(DataObject.class);         assert obj != null;     }     @Override     public JComponent getVisualRepresentation() {         return this;     }     @Override     public JComponent getToolbarRepresentation() {         return toolbar;     }     @Override     public Action[] getActions() {         return new Action[0];     }     @Override     public Lookup getLookup() {         return obj.getLookup();     }     @Override     public void componentOpened() {     }     @Override     public void componentClosed() {     }     @Override     public void componentShowing() {     }     @Override     public void componentHidden() {     }     @Override     public void componentActivated() {     }     @Override     public void componentDeactivated() {     }     @Override     public UndoRedo getUndoRedo() {         return UndoRedo.NONE;     }     @Override     public void setMultiViewCallback(MultiViewElementCallback mvec) {         this.mvec = mvec;     }     @Override     public CloseOperationState canCloseElement() {         return CloseOperationState.STATE_OK;     } } It's a fair amount of code, but mostly pretty self-explanatory. The loosely coupled tabs are applicable to all NetBeans editors, not just the Java editor, which is why the "History" tab is now available to all editors throughout NetBeans IDE. In the next blog entry, you'll see the integration of the Visual Library into the panel I embedded in the Java editor.

    Read the article

  • Stop method not working

    - by avoq
    Hi everyone , can anybody tell me why the following code doesn't work properly? I want to play and stop an audio file. I can do the playback but whenever I click the stop button nothing happens. Here's the code : Thank you. .................. import java.io.*; import javax.sound.sampled.*; import javax.swing.*; import java.awt.event.*; public class SoundClipTest extends JFrame { final JButton button1 = new JButton("Play"); final JButton button2 = new JButton("Stop"); int stopPlayback = 0; // Constructor public SoundClipTest() { button1.setEnabled(true); button2.setEnabled(false); // button play button1.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ button1.setEnabled(false); button2.setEnabled(true); play(); }// end actionPerformed }// end ActionListener );// end addActionListener() // button stop button2.addActionListener( new ActionListener(){ public void actionPerformed( ActionEvent e){ //Terminate playback before EOF stopPlayback = 1; }//end actionPerformed }//end ActionListener );//end addActionListener() this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setTitle("Test Sound Clip"); this.setSize(300, 200); JToolBar bar = new JToolBar(); bar.add(button1); bar.add(button2); bar.setOrientation(JToolBar.VERTICAL); add("North", bar); add("West", bar); setVisible(true); } void play() { try { final File inputAudio = new File("first.wav"); // First, we get the format of the input file final AudioFileFormat.Type fileType = AudioSystem.getAudioFileFormat(inputAudio).getType(); // Then, we get a clip for playing the audio. final Clip c = AudioSystem.getClip(); // We get a stream for playing the input file. AudioInputStream ais = AudioSystem.getAudioInputStream(inputAudio); // We use the clip to open (but not start) the input stream c.open(ais); // We get the format of the audio codec (not the file format we got above) final AudioFormat audioFormat = ais.getFormat(); c.start(); if (stopPlayback == 1 ) {c.stop();} } catch (UnsupportedAudioFileException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (LineUnavailableException e) { e.printStackTrace(); } }// end play public static void main(String[] args) { //new SoundClipTest().play(); new SoundClipTest(); } }

    Read the article

  • Using getters/setters in Java

    - by Crystal
    I'm having some trouble with the idea of accessing variables from other classes. I had a post here: http://stackoverflow.com/questions/3011642/having-access-to-a-private-variable-from-other-classes-in-java where I got some useful information, and thought an example would be better show it, and ask a separate question as well. I have a form that I can input data to, and it has a List variable. I didn't make it static at first, but I thought if I needed to get the total size from another class, then I wouldn't create an instance of that class in order to use the function to getTotalContacts. I basically want to update my status bar with the total number of contacts that are in my list. One of the members said in the above post to use the original Foo member to get the contacts, but I'm not sure how that works in this case. Any thoughts would be appreciated. Thanks. import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.List; import java.util.ArrayList; public class AddressBook { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { AddressBookFrame frame = new AddressBookFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu fileMenu = new JMenu("File"); JMenuItem openItem = new JMenuItem("Open"); JMenuItem saveItem = new JMenuItem("Save"); JMenuItem saveAsItem = new JMenuItem("Save As"); JMenuItem printItem = new JMenuItem("Print"); JMenuItem exitItem = new JMenuItem("Exit"); fileMenu.add(openItem); fileMenu.add(saveItem); fileMenu.add(saveAsItem); fileMenu.add(printItem); fileMenu.add(exitItem); menuBar.add(fileMenu); JMenu editMenu = new JMenu("Edit"); JMenuItem newItem = new JMenuItem("New"); JMenuItem editItem = new JMenuItem("Edit"); JMenuItem deleteItem = new JMenuItem("Delete"); JMenuItem findItem = new JMenuItem("Find"); JMenuItem firstItem = new JMenuItem("First"); JMenuItem previousItem = new JMenuItem("Previous"); JMenuItem nextItem = new JMenuItem("Next"); JMenuItem lastItem = new JMenuItem("Last"); editMenu.add(newItem); editMenu.add(editItem); editMenu.add(deleteItem); editMenu.add(findItem); editMenu.add(firstItem); editMenu.add(previousItem); editMenu.add(nextItem); editMenu.add(lastItem); menuBar.add(editMenu); JMenu helpMenu = new JMenu("Help"); JMenuItem documentationItem = new JMenuItem("Documentation"); JMenuItem aboutItem = new JMenuItem("About"); helpMenu.add(documentationItem); helpMenu.add(aboutItem); menuBar.add(helpMenu); frame.setVisible(true); } }); } } class AddressBookFrame extends JFrame { public AddressBookFrame() { setLayout(new BorderLayout()); setTitle("Address Book"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); AddressBookToolBar toolBar = new AddressBookToolBar(); add(toolBar, BorderLayout.NORTH); AddressBookStatusBar aStatusBar = new AddressBookStatusBar(); add(aStatusBar, BorderLayout.SOUTH); AddressBookForm form = new AddressBookForm(); add(form, BorderLayout.CENTER); } public static final int DEFAULT_WIDTH = 500; public static final int DEFAULT_HEIGHT = 500; } /* Create toolbar buttons and add buttons to toolbar */ class AddressBookToolBar extends JPanel { public AddressBookToolBar() { setLayout(new FlowLayout(FlowLayout.LEFT)); JToolBar bar = new JToolBar(); JButton newButton = new JButton("New"); JButton editButton = new JButton("Edit"); JButton deleteButton = new JButton("Delete"); JButton findButton = new JButton("Find"); JButton firstButton = new JButton("First"); JButton previousButton = new JButton("Previous"); JButton nextButton = new JButton("Next"); JButton lastButton = new JButton("Last"); bar.add(newButton); bar.add(editButton); bar.add(deleteButton); bar.add(findButton); bar.add(firstButton); bar.add(previousButton); bar.add(nextButton); bar.add(lastButton); add(bar); } } /* Creates the status bar string */ class AddressBookStatusBar extends JPanel { public AddressBookStatusBar() { setLayout(new FlowLayout(FlowLayout.LEFT)); this.statusBarString = new JLabel("Total: " + AddressBookForm.getTotalContacts()); add(this.statusBarString); } public void updateLabel() { contactsLabel.setText(AddressBookForm.getTotalContacts().toString()); } private JLabel statusBarString; private JLabel contactsLabel; } class AddressBookForm extends JPanel { public AddressBookForm() { // create form panel this.setLayout(new GridLayout(2, 1)); JPanel formPanel = new JPanel(); formPanel.setLayout(new GridLayout(4, 2)); firstName = new JTextField(20); lastName = new JTextField(20); telephone = new JTextField(20); email = new JTextField(20); JLabel firstNameLabel = new JLabel("First Name: ", JLabel.LEFT); formPanel.add(firstNameLabel); formPanel.add(firstName); JLabel lastNameLabel = new JLabel("Last Name: ", JLabel.LEFT); formPanel.add(lastNameLabel); formPanel.add(lastName); JLabel telephoneLabel = new JLabel("Telephone: ", JLabel.LEFT); formPanel.add(telephoneLabel); formPanel.add(telephone); JLabel emailLabel = new JLabel("Email: ", JLabel.LEFT); formPanel.add(emailLabel); formPanel.add(email); add(formPanel); // create button panel JPanel buttonPanel = new JPanel(); JButton insertButton = new JButton("Insert"); JButton displayButton = new JButton("Display"); ActionListener insertAction = new AddressBookListener(); ActionListener displayAction = new AddressBookListener(); insertButton.addActionListener(insertAction); displayButton.addActionListener(displayAction); buttonPanel.add(insertButton); buttonPanel.add(displayButton); add(buttonPanel); } public static int getTotalContacts() { return addressList.size(); } //void addContact(Person contact); private JTextField firstName; private JTextField lastName; private JTextField telephone; private JTextField email; private JLabel contacts; private static List<Person> addressList = new ArrayList<Person>(); private class AddressBookListener implements ActionListener { public void actionPerformed(ActionEvent e) { String buttonPressed = e.getActionCommand(); System.out.println(buttonPressed); if (buttonPressed == "Insert") { Person aPerson = new Person(firstName.getText(), lastName.getText(), telephone.getText(), email.getText()); addressList.add(aPerson); } else { for (Person p : addressList) { System.out.println(p); } } } } } My other question is why do I get the error, "int cannot be dereferenced contactsLabel.setText(AddressbookForm.getTotalContacts().toString()); Thanks!

    Read the article

  • Passing ActionListeners in Java, pack()

    - by Crystal
    Two questions. First question is I'm trying to create a simple form that when you press a button, it adds a Person object to the ArrayList. However, since I am not used to GUIs, I tried creating one and am first just trying to get the user input from the JTextField, create an ActionListener object of the appropriate type, so once that works, then I can pass in all the JTextField inputs to create my Person object. Unfortunately, I am not getting any data when I type in something to the firstName JTextField and was wondering if someone could look at my code below. import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.List; import java.util.ArrayList; public class AddressBook { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { AddressBookFrame frame = new AddressBookFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu fileMenu = new JMenu("File"); JMenuItem openItem = new JMenuItem("Open"); JMenuItem saveItem = new JMenuItem("Save"); JMenuItem saveAsItem = new JMenuItem("Save As"); JMenuItem printItem = new JMenuItem("Print"); JMenuItem exitItem = new JMenuItem("Exit"); fileMenu.add(openItem); fileMenu.add(saveItem); fileMenu.add(saveAsItem); fileMenu.add(printItem); fileMenu.add(exitItem); menuBar.add(fileMenu); JMenu editMenu = new JMenu("Edit"); JMenuItem newItem = new JMenuItem("New"); JMenuItem editItem = new JMenuItem("Edit"); JMenuItem deleteItem = new JMenuItem("Delete"); JMenuItem findItem = new JMenuItem("Find"); JMenuItem firstItem = new JMenuItem("First"); JMenuItem previousItem = new JMenuItem("Previous"); JMenuItem nextItem = new JMenuItem("Next"); JMenuItem lastItem = new JMenuItem("Last"); editMenu.add(newItem); editMenu.add(editItem); editMenu.add(deleteItem); editMenu.add(findItem); editMenu.add(firstItem); editMenu.add(previousItem); editMenu.add(nextItem); editMenu.add(lastItem); menuBar.add(editMenu); JMenu helpMenu = new JMenu("Help"); JMenuItem documentationItem = new JMenuItem("Documentation"); JMenuItem aboutItem = new JMenuItem("About"); helpMenu.add(documentationItem); helpMenu.add(aboutItem); menuBar.add(helpMenu); frame.setVisible(true); } }); } } class AddressBookFrame extends JFrame { public AddressBookFrame() { setLayout(new BorderLayout()); setTitle("Address Book"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); AddressBookToolBar toolBar = new AddressBookToolBar(); add(toolBar, BorderLayout.NORTH); AddressBookStatusBar aStatusBar = new AddressBookStatusBar("5"); add(aStatusBar, BorderLayout.SOUTH); AddressBookForm form = new AddressBookForm(); add(form, BorderLayout.CENTER); } public static final int DEFAULT_WIDTH = 500; public static final int DEFAULT_HEIGHT = 500; } /* Create toolbar buttons and add buttons to toolbar */ class AddressBookToolBar extends JPanel { public AddressBookToolBar() { setLayout(new FlowLayout(FlowLayout.LEFT)); JToolBar bar = new JToolBar(); JButton newButton = new JButton("New"); JButton editButton = new JButton("Edit"); JButton deleteButton = new JButton("Delete"); JButton findButton = new JButton("Find"); JButton firstButton = new JButton("First"); JButton previousButton = new JButton("Previous"); JButton nextButton = new JButton("Next"); JButton lastButton = new JButton("Last"); bar.add(newButton); bar.add(editButton); bar.add(deleteButton); bar.add(findButton); bar.add(firstButton); bar.add(previousButton); bar.add(nextButton); bar.add(lastButton); add(bar); } } /* Creates the status bar string */ class AddressBookStatusBar extends JPanel { public AddressBookStatusBar(String statusBarString) { setLayout(new FlowLayout(FlowLayout.LEFT)); this.statusBarString = new JLabel("Total number of people: " + statusBarString); add(this.statusBarString); } private JLabel statusBarString; private int totalContacts; } class AddressBookForm extends JPanel { public AddressBookForm() { this.setLayout(new GridLayout(2, 1)); JPanel formPanel = new JPanel(); formPanel.setLayout(new GridLayout(4, 2)); JTextField firstName = new JTextField(20); JTextField lastName = new JTextField(20); JTextField telephone = new JTextField(20); JTextField email = new JTextField(20); JLabel firstNameLabel = new JLabel("First Name: ", JLabel.LEFT); formPanel.add(firstNameLabel); formPanel.add(firstName); JLabel lastNameLabel = new JLabel("Last Name: ", JLabel.LEFT); formPanel.add(lastNameLabel); formPanel.add(lastName); JLabel telephoneLabel = new JLabel("Telephone: ", JLabel.LEFT); formPanel.add(telephoneLabel); formPanel.add(telephone); JLabel emailLabel = new JLabel("Email: ", JLabel.LEFT); formPanel.add(emailLabel); formPanel.add(email); add(formPanel); JPanel buttonPanel = new JPanel(); JButton insertButton = new JButton("Insert"); JButton displayButton = new JButton("Display"); // create button actions AddressBookManager insertAction = new AddressBookManager(firstName.getText()); insertButton.addActionListener(insertAction); buttonPanel.add(insertButton); buttonPanel.add(displayButton); add(buttonPanel); } private List<Person> addressList = new ArrayList<Person>(); private class AddressBookManager implements ActionListener { public AddressBookManager(String text) { // addressList.add( setName(text); System.out.println("Test" + text); } public void actionPerformed(ActionEvent e) { System.out.println("Hello" + name); } public void setName(String name) { this.name = name; } private String name; } } Second question is, how do I make my form not take up the whole center space. I don't like the stretch look and was hoping the JTextFields could be just one line long, not a big box. Same thing with the buttons. Any thoughts? Thanks.

    Read the article

  • JSplitPane overlaps JButtons in BorderLayout, but does not when layout is null

    - by thaweatherman
    So I'm having another issue..... I'm currently using a BorderLayout in my GUI so that when I resize my jframe, all of the internal components resize with it. I couldn't get any other layout to work with how I want the GUI to look while providing this resizing capability. At the top I have a JMenuBar, and below it I have a bunch of buttons. Below that I am supposed to have a JSplitPane, and it is there. However, the buttons seemed to be contained within the JSplitPane, which is not my intention. So when anything happens within the splitpane, the buttons disappear until I move my mouse over them again. When I set my layout to null everything works great except I lose the resizing capability, which is not good. Tried posting images but it wont let me since my rep isnt at 10 yet :( Any suggestions? I've tried putting the buttons into a JPanel then adding the jpanel but the splitpane overlaps with that. Same with a JToolBar. The order in which I add my items is: 1) the menu bar setJMenuBar(menuBar) 2) the buttons getContentPane().add(btnZoomIn) etc. 3) the split pane getContentPane().add(splitPane) then the rest of the things you see after that

    Read the article

  • Visual View for Schema Based Editor

    - by Geertjan
    Starting from yesterday's blog entry, make the following change in the DataObject's constructor: registerEditor("text/x-sample+xml", true); I.e., the MultiDataObject.registerEditor method turns the editor into a multiview component. Now, again, within the DataObject, add the following, to register a source editor in the multiview component: @MultiViewElement.Registration(         displayName = "#LBL_Sample_Source",         mimeType = "text/x-sample+xml",         persistenceType = TopComponent.PERSISTENCE_NEVER,         preferredID = "ShipOrderSourceView",         position = 1000) @NbBundle.Messages({     "LBL_Sample_Source=Source" }) public static MultiViewElement createEditor(Lookup lkp){     return new MultiViewEditorElement(lkp); } Result: Next, let's create a visual editor in the multiview component. This could be within the same module as the above or within a completely separate module. That makes it possible for external contributors to provide modules with new editors in an existing multiview component: @MultiViewElement.Registration(displayName = "#LBL_Sample_Visual", mimeType = "text/x-sample+xml", persistenceType = TopComponent.PERSISTENCE_NEVER, preferredID = "VisualEditorComponent", position = 500) @NbBundle.Messages({ "LBL_Sample_Visual=Visual" }) public class VisualEditorComponent extends JPanel implements MultiViewElement {     public VisualEditorComponent() {         initComponents();     }     @Override     public String getName() {         return "VisualEditorComponent";     }     @Override     public JComponent getVisualRepresentation() {         return this;     }     @Override     public JComponent getToolbarRepresentation() {         return new JToolBar();     }     @Override     public Action[] getActions() {         return new Action[0];     }     @Override     public Lookup getLookup() {         return Lookup.EMPTY;     }     @Override     public void componentOpened() {     }     @Override     public void componentClosed() {     }     @Override     public void componentShowing() {     }     @Override     public void componentHidden() {     }     @Override     public void componentActivated() {     }     @Override     public void componentDeactivated() {     }     @Override     public UndoRedo getUndoRedo() {         return UndoRedo.NONE;     }     @Override     public void setMultiViewCallback(MultiViewElementCallback callback) {     }     @Override     public CloseOperationState canCloseElement() {         return CloseOperationState.STATE_OK;     } } Result: Next, the DataObject is automatically returned from the Lookup of DataObject. Therefore, you can go back to your visual editor, add a LookupListener, listen for DataObjects, parse the underlying XML file, and display values in GUI components within the visual editor.

    Read the article

1