Search Results

Search found 108 results on 5 pages for 'gridlayout'.

Page 1/5 | 1 2 3 4 5  | Next Page >

  • How to get the coordinate of Gridlayout

    - by Jessy
    Hi, I set my JPanel to GridLayout (6,6), with dimension (600,600) Each cell of the grid will display one pictures with different widths and heights. The picture first add to a JLabel, and the JLabel then added to the cells. How can retrieved the coordinate of the pictures in the cells and not the coordinate of cells? So far the out give these coordinate which equal height and width even on screen the pictures showed in different sizes. e.g. java.awt.Rectangle[x=100,y=100,width=100,height=100] java.awt.Rectangle[x=200,y=100,width=100,height=100] java.awt.Rectangle[x=300,y=100,width=100,height=100] The reason why I used GridLayout instead of gridBagLayout is that, I want each pictures to have boundary. If I use GridBagLayout, the grid will expand according to the picture size. I want grid size to be in fix size. JPanel pDraw = new JPanel(new GridLayout(6,6)); pDraw.setPreferredSize(new Dimension(600,600)); for (int i =0; i<(6*6); i++) { //get random number for height and width of the image int x = rand.nextInt(40)+(50); int y = rand.nextInt(40)+(50); ImageIcon icon = createImageIcon("bird.jpg"); //rescale the image according to the size selected Image img = icon.getImage().getScaledInstance(x,y,img.SCALE_SMOOTH); icon.setImage(img ); JLabel label = new JLabel(icon); pDraw.add(label); } for(Component component:components) { //retrieve the coordinate System.out.println(component.getBounds()); }

    Read the article

  • java, swing, Gridlayout problem

    - by josh
    I have a panel with GridLayout But when I'm trying to run the program, only the first button out of 100 is shown. Futhermore, the rest appear only when I move the cursor over them. What's wrong with it? Here's the whole class(Life.CELLS=10 and CellButton is a class which extends JButton) public class MainLayout extends JFrame { public MainLayout() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(650, 750); setLayout(new FlowLayout()); //setResizable(false); final JPanel gridPanel = new JPanel(new GridLayout(Life.CELLS, Life.CELLS)); for (int i=0; i<Life.CELLS; i++) { for (int j=0; j<Life.CELLS; j++) { CellButton jb = new CellButton(i, j); jb.setPreferredSize(new Dimension(jb.getIcon().getIconHeight(), jb.getIcon().getIconWidth())); buttons[i][j] = jb; grid[i][j] = false; gridPanel.add(jb); } } add(gridPanel); } } This is code of CellButton package classes; import javax.swing.JButton; import javax.swing.ImageIcon; import javax.swing.JFrame; public class CellButton extends JButton { private int x; private int y; boolean alive; ImageIcon icon; boolean next; // icons for grids final ImageIcon dead = new ImageIcon(JFrame.class.getResource("/images/image1.gif")); final ImageIcon live = new ImageIcon(JFrame.class.getResource("/images/image2.gif")); public CellButton(int X, int Y) { super(); x = X; y = Y; alive = false; icon = dead; setIcon(icon); } public int getX() { return x; } public int getY() { return y; } public boolean isAlive() { return alive; } public void relive() { alive = true; icon = live; setIcon(icon); } public void die() { alive = false; icon = dead; setIcon(icon); } public void setNext(boolean n) { next = n; } public boolean getNext() { return next; } public ImageIcon getIcon() { return icon; } }

    Read the article

  • How to get components from a JFrame with a GridLayout?

    - by NlightNfotis
    I have a question about Java and JFrame in particular. Let's say I have a JFrame that I am using with a GridLayout. Supposing that I have added JButtons in the JFrame, how can I gain access to the one I want using it's position (by position, I mean a x and a y, used to define the exact place on the Grid). I have tried several methods, for instance getComponentAt(int x, int y), and have seen that those methods do not work as intended when combined with GridLayout, or at least don't work as intended in my case. So I tried using getComponent(), which seems fine. The latest method, that seems to be on a right track for me is (assuming I have a JFrame with a GridLayout with 7 rows and 7 columns, x as columns, y as rows): public JButton getButtonByXAndY(int x, int y) { return (JButton) this.getContentPane().getComponent((y-1) * 7 + x); } Using the above, say I want to get the JButton at (4, 4), meaning the 25th JButton in the JFrame, I would index through the first 21 buttons at first, and then add 4 more, finally accessing the JButton I want. Problem is this works like that in theory only. Any ideas? P.S sorry for linking to an external website, but stack overflow won't allow me to upload the image, because I do not have the required reputation.

    Read the article

  • Piano Keys using GridLayout (or Something Else)

    - by yar
    I am creating a container of JComponents which will look like a piano keyboard. The black keys look like this (Groovy) def setBlackNotes(buttons) { def octaves = (int)(buttons.size() / 5) def gridLayout = new GridLayout(1, octaves*7); def blackNotePanel = new JPanel(gridLayout) this.add blackNotePanel def i = 0 octaves.times { 2.times { blackNotePanel.add buttons[i++] } blackNotePanel.add Box.createHorizontalBox() 3.times { blackNotePanel.add buttons[i++] } blackNotePanel.add Box.createHorizontalBox() } } Which is just what I need, and looks like this: but then I'd like to move this over to the right by half-a-key width. All of my attempts to move the blackNotePanel over by an arbitrary width -- wrapping it a BorderLayout, a MigLayout, etc. -- have failed or changed the spacing of the GridLayout radically. Any suggestions on how to move this over to the right by an arbitrary amount in pixels?

    Read the article

  • GridLayout with single column

    - by Albinoswordfish
    Right now I'm trying to use a GridLayout with only a single column. However I'm having a problem where I don't want the object, in this case a JButton, to be stretched the entire width of the JPanel that it's on. Is there a way to decrease the width of the JButton so that it does not stretch the entire width of the JPanel. I've tried using setPreferredSize and setSize with no results. Is this just the way GridLayout works or is there something I'm missing?

    Read the article

  • About GridLayout.

    - by Knowing me knowing you
    Hi, if I have code like so: class X extends JFrame { X() { setLayout(new GridLayout(3,3)); JButton b = new JButton("A-ha"); /*I would like to add this button in the center of this grid (2,2)*/ //How can I do it? } }; Thanks.

    Read the article

  • How to add two label in one gridbox?

    - by Jessy
    Hello everyone, How can I add two label in the same grid box? e.g. in row 1, col 1 the will be 2 labels? The code below will add the label in two different grid. JPanel chckBox = new JPanel(new GridLayout(1,8,3,3)); JLabel label1 = new JLabel("A"); JLabel label2 = new JLabel("B"); ... chckBox.add(label1); chckBox.add(label2); ...

    Read the article

  • Control vertical source ordering with 960.gs?

    - by Ztyx
    Hi, I've understood it's possible to control the vertical (columnwise) source ordering with the 960 Grid System. However, is it possible to do something similar vertically? If not, does anyone know of any grid system that handles source ordering vertically? Thanks, Jens

    Read the article

  • Flex - Repeater Component with Grid Layout

    - by davidemm
    I have a randomly-sized array of items. I'd like to display one label for each item in a Repeater component. I want them to display in a grid layout with 5 columns and as many rows as needed. How do I do that in Flex / ActionScript? Maybe there's another way to do it that I haven't seen yet, so any suggestion are appreciated. Thanks!

    Read the article

  • How to set the component size with GridLayout? Is there a better way?

    - by Blackbam
    Hello guys, I am working on a larger GUI with Java and I am becoming angry on Layout Managers. I have a "Settings-Panel" with a variable number of JComponents in it (Labels, Buttons, JSpinners, JSliders,...). I just want the following: JLabel <- JComponent JLabel <- JComponent JLabel <- JComponent ... My Panel has a size of 500px, so that there is enough space for a lot of components. Unfortunatly the GridLayout always stretches the size of the Components to the whole Panel, even if I set a MaximumSize for every component. It looks stupid if there are only two buttons each with a height of 250px. I tried flow Layout, but i cannot figure out a way to make new lines properly. I tried BoxLayout.Y_AXIS, but the Components are always centered, and Label and Component are not in the same line. Does anybody know a good and short way with LayoutManagers to handle this properly?

    Read the article

  • proper way to creation multiple similiar buttons/panels

    - by JayAvon
    I have the below Code which i tried to do, but it only shows(the minus/plus button) on the last GirdLayout (Intelligence stat): JButton plusButton = new JButton("+"); JButton minusButton = new JButton("-"); statStrengthGridPanel = new JPanel(new GridLayout(1,3)); statStrengthGridPanel.add(minusButton); statStrengthGridPanel.add(new JLabel("10")); statStrengthGridPanel.add(plusButton); statConstitutionGridPanel = new JPanel(new GridLayout(1,3)); statConstitutionGridPanel.add(minusButton); statConstitutionGridPanel.add(new JLabel("10")); statConstitutionGridPanel.add(plusButton); statDexterityGridPanel = new JPanel(new GridLayout(1,3)); statDexterityGridPanel.add(minusButton); statDexterityGridPanel.add(new JLabel("10")); statDexterityGridPanel.add(plusButton); statIntelligenceGridPanel = new JPanel(new GridLayout(1,3)); statIntelligenceGridPanel.add(minusButton); statIntelligenceGridPanel.add(new JLabel("10")); statIntelligenceGridPanel.add(plusButton); I know I can do something like I did for the Panel names(have multiple ones), but I did not want to do that for the Panels in the first place. I am trying to use best practice and not have my code be repetitive. Any suggestions?? The goal is to have 4 stats, to assign points to, with decrement and increment buttons(I decided against sliders). Eventually I will have them have upper and lower limits, decrement the "unused" label, and all of that good stuff, but I just want to not be repetitive. Thanks for any help.

    Read the article

  • How can I set size of a button?

    - by Roman
    I put my buttons in a JPane with GridLayout. Then I put JPanel into another JPanel with BoxLayout.Y_AXIS. I want buttons in the GridLayout to be square. I use tmp.setSize(30,30) and it does not work. I also try to use new GridLayout(X, Y, 4, 4) but I cannot figure out what X and Y are. So, what is the correct way to do this stuff?

    Read the article

  • A "Trig" Calculating Class

    - by Clinton Scott
    I have been trying to create a gui that calculates trigonometric functions based off of the user's input. I have had success in the GUI part, but my class that I wrote to hold information using inheritance seems to be messed up, because when I run it gives an error saying: Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - constructor ArcTrigCalcCon in class TrigCalc.ArcTrigCalcCon cannot be applied to given types; required: double,double,double,double,double,double found: java.lang.Double,java.lang.Double,java.lang.Double reason: actual and formal argument lists differ in length at TrigCalc.TrigCalcGUI.(TrigCalcGUI.java:31) at TrigCalc.TrigCalcGUI.main(TrigCalcGUI.java:87) Java Result: 1 and says it is the object causing the problem. Below Will be my code. First I will put up my inheritance class with cosecant secant and cotangent and then my original class with the original 3 trig functions: { public ArcTrigCalcCon(double s, double cs, double t, double csc, double sc, double ct) { // Inherit from the Trig Calc class super(s, cs, t); cosecant = 1/s; secant = 1/cs; cotangent = 1/t; } public void setCsc(double csc) { cosecant = csc; } public void setSec(double sc) { secant = sc; } public void setCot(double ct) { cotangent = ct; } } Here is the first Trigonometric class: public class TrigCalcCon { public double sine; public double cosine; public double tangent; public TrigCalcCon(double s, double cs, double t) { sine = s; cosine = cs; tangent = t; } public void setSin(double s) { sine = s; } public void setCos(double cs) { cosine = cs; } public void setTan(double t) { tangent = t; } public void set(double s, double cs, double t) { sine = s; cosine = cs; tangent = t; } public double getSin() { return Math.sin(sine); } public double getCos() { return Math.cos(cosine); } public double getTan() { return Math.tan(tangent); } } and here is the demo class to run the gui: public class TrigCalcGUI extends JFrame implements ActionListener { // Instance Variables private String input; private Double s, cs, t, csc, sc, ct; private JPanel mainPanel, sinPanel, cosPanel, tanPanel, cscPanel, secPanel, cotPanel, buttonPanel, inputPanel, displayPanel; // Panel Display private JLabel sinLabel, cosLabel, tanLabel, secLabel, cscLabel, cotLabel, inputLabel; private JTextField sinTF, cosTF, tanTF, secTF, cscTF, cotTF, inputTF; //Text Fields for sin, cos, and tan, and inverse private JButton calcButton, clearButton; // Calculate and Exit Buttons // Object ArcTrigCalcCon trC = new ArcTrigCalcCon(s, cs, t); public TrigCalcGUI() { // title bar text. super("Trig Calculator"); // Corner exit button action. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create main panel to add each panel to mainPanel = new JPanel(); mainPanel.setLayout(new GridLayout(3,2)); displayPanel = new JPanel(); displayPanel.setLayout(new GridLayout(3,2)); // Assign Panel to each variable inputPanel = new JPanel(); sinPanel = new JPanel(); cosPanel = new JPanel(); tanPanel = new JPanel(); cscPanel = new JPanel(); secPanel = new JPanel(); cotPanel = new JPanel(); buttonPanel = new JPanel(); // Call each constructor buildInputPanel(); buildSinCosTanPanels(); buildCscSecCotPanels(); buildButtonPanel(); // Add each panel to content pane displayPanel.add(sinPanel); displayPanel.add(cscPanel); displayPanel.add(cosPanel); displayPanel.add(secPanel); displayPanel.add(tanPanel); displayPanel.add(cotPanel); // Add three content panes to GUI mainPanel.add(inputPanel, BorderLayout.NORTH); mainPanel.add(displayPanel, BorderLayout.CENTER); mainPanel.add(buttonPanel, BorderLayout.SOUTH); //add mainPanel this.add(mainPanel); // size of window to content this.pack(); // display window setVisible(true); } public static void main(String[] args) { new TrigCalcGUI(); } private void buildInputPanel() { inputLabel = new JLabel("Enter a Value: "); inputTF = new JTextField(5); inputPanel.add(inputLabel); inputPanel.add(inputTF); } // Building Constructor for sinPanel cosPanel, and tanPanel private void buildSinCosTanPanels() { // Set layout and border for sinPanel sinPanel.setLayout(new GridLayout(2,2)); sinPanel.setBorder(BorderFactory.createTitledBorder("Sine")); // sinTF = new JTextField(5); sinTF.setEditable(false); sinPanel.add(sinTF); // Set layout and border for cosPanel cosPanel.setLayout(new GridLayout(2,2)); cosPanel.setBorder(BorderFactory.createTitledBorder("Cosine")); cosTF = new JTextField(5); cosTF.setEditable(false); cosPanel.add(cosTF); // Set layout and border for tanPanel tanPanel.setLayout(new GridLayout(2,2)); tanPanel.setBorder(BorderFactory.createTitledBorder("Tangent")); tanTF = new JTextField(5); tanTF.setEditable(false); tanPanel.add(tanTF); } // Building Constructor for cscPanel secPanel, and cotPanel private void buildCscSecCotPanels() { // Set layout and border for cscPanel cscPanel.setLayout(new GridLayout(2,2)); cscPanel.setBorder(BorderFactory.createTitledBorder("Cosecant")); // cscTF = new JTextField(5); cscTF.setEditable(false); cscPanel.add(cscTF); // Set layout and border for secPanel secPanel.setLayout(new GridLayout(2,2)); secPanel.setBorder(BorderFactory.createTitledBorder("Secant")); secTF = new JTextField(5); secTF.setEditable(false); secPanel.add(secTF); // Set layout and border for cotPanel cotPanel.setLayout(new GridLayout(2,2)); cotPanel.setBorder(BorderFactory.createTitledBorder("Cotangent")); cotTF = new JTextField(5); cotTF.setEditable(false); cotPanel.add(cotTF); } private void buildButtonPanel() { // Create buttons and add events calcButton = new JButton("Calculate"); calcButton.addActionListener(new CalcButtonListener()); clearButton = new JButton("Clear"); clearButton.addActionListener(new ClearButtonListener()); buttonPanel.add(calcButton); buttonPanel.add(clearButton); } @Override public void actionPerformed(ActionEvent e) { } private class CalcButtonListener implements ActionListener { public void actionPerformed(ActionEvent ae) { // Declare boolean variable boolean incorrect = true; // Set input variable to input text field text input = inputTF.getText(); ImageIcon newIcon; ImageIcon frowny = new ImageIcon(TrigCalcGUI.class.getResource("/Sad_Face.png")); Image gm = frowny.getImage(); Image newFrowny = gm.getScaledInstance(100, 100, java.awt.Image.SCALE_FAST); newIcon = new ImageIcon(newFrowny); // If boolean is true, throw exception if(incorrect) { try{Double.parseDouble(input); incorrect = false;} catch(NumberFormatException nfe) { String s = "Invalid Input " + "/n Input Must Be a Numerical value." + "/nPlease Press Ok and Try Again"; JOptionPane.showMessageDialog(null, s, "Invalid", JOptionPane.ERROR_MESSAGE, newIcon); inputTF.setText(""); inputTF.requestFocus(); } } // If boolean is not true, proceed with output if (incorrect != true) { /* Set each text field's output to the String double value * of inputTF */ sinTF.setText(input); cosTF.setText(input); tanTF.setText(input); cscTF.setText(input); secTF.setText(input); cotTF.setText(input); } } } /** * Private inner class that handles the event when * the user clicks the Exit button. */ private class ClearButtonListener implements ActionListener { public void actionPerformed(ActionEvent ae) { // Clear field sinTF.setText(""); cosTF.setText(""); tanTF.setText(""); cscTF.setText(""); secTF.setText(""); cotTF.setText(""); // Clear textfield and set cursor focus to field inputTF.setText(""); inputTF.requestFocus(); } } }

    Read the article

  • Java SWT - placing image buttons on the image background

    - by foma
    I am trying to put buttons with images(gif) on the background which has already been set as an image (shell.setBackgroundImage(image)) and I can't figure out how to remove transparent border around buttons with images. I would be grateful if somebody could give me some tip about this issue. Here is my code: import org.eclipse.swt.widgets.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; public class Main_page { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Image image = new Image(display, "bg.gif"); shell.setBackgroundImage(image); shell.setBackgroundMode(SWT.INHERIT_DEFAULT); shell.setFullScreen(true); Button button = new Button(shell, SWT.PUSH); button.setImage(new Image(display, "button.gif")); RowLayout Layout = new RowLayout(); shell.setLayout(Layout); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } } Sorceror, thanks for your answer I will definitely look into this article. Maybe I will find my way. So far I have improved my code a little bit. Firstly, I managed to get rid of the gray background noise. Secondly, I finally succeeded in creating the button as I had seen it in the first place. Yet, another obstacle has arisen. When I removed image(button) transparent border it turned out that the button change its mode(from push button to check box). The problem is that I came so close to the thing I was looking for and now I am a little puzzled. If you have some time please give a glance at my code. Here is the code, if you launch it you will see what the problem is(hope you didn't have problems downloading images): import org.eclipse.swt.widgets.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; public class Main_page { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Image image = new Image(display, "bg.gif"); // Launch on a screen 1280x1024 shell.setBackgroundImage(image); shell.setBackgroundMode(SWT.TRANSPARENT); shell.setFullScreen(true); GridLayout gridLayout = new GridLayout(); gridLayout.marginTop = 200; gridLayout.marginLeft = 20; shell.setLayout(gridLayout); // If you replace SWT.PUSH with SWT.COLOR_TITLE_INACTIVE_BACKGROUND // you will see what I am looking for, despite nasty check box Button button = new Button(shell, SWT.PUSH); button.setImage(new Image(display, "moneyfast.gif")); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }

    Read the article

  • How to access widgets created within functions in later function calls in Qt

    - by Inanepenguin
    So currently I have code, in C++, that creates a few QLabels, a QLineEdit, and a QCheckBox when a selection is made from a QComboBox. However, I would like to be able to access the widgets I have created in a later function to destroy them if a new selection is made from the combo box. I am able to access the objects created from using the Designer by doing ui-Object but i am not able to do that with objects created by using my own code. Can I do that some how, because I know how to work with that. In short, I would like to be able to dynamically create/destroy QWidgets based on selections made by the user. Is there a reference I should know of to do this, or any documentation? Or am I just completely going about this the wrong way? Here is the code I presently have for creating the objects: if (eventType == QString::fromStdString("Birthday")) { QLabel *label1 = new QLabel ("Celebrant: "); QLabel *label2 = new QLabel ("Surprise: "); QLineEdit *lineEdit = new QLineEdit; QCheckBox *box = new QCheckBox; ui->gridLayout->addWidget(label1,3,0,1,1, 0); ui->gridLayout->addWidget(label2,4,0,1,1,0); ui->gridLayout->addWidget(lineEdit,3,1,1,1,0); ui->gridLayout->addWidget(box,4,1,1,2,0); }

    Read the article

  • Problems using Custom Layout in XML

    - by Kevin
    I've created a new GridLayout class that I want to use in an XML File. The class is in another project. I've created the attrs.xml file in the other project with my properties but when the constructor gets called with the AttributeSet, none of the values are set. In my xml for my screen layout, I refer to the layout with the following: xmlns:gridLayout="@com.mastertechsoftware.AndroidUtil:http://schemas.android.com/apk/res/com.mastertechsoftware.AndroidUtil" Not sure if that is right. I have the attrs.xml file being compiled to R.java in com/mastertechsoftware/AndroidUtil. All the right styleable values are there. In my constructor, I use: TypedArray a = c .obtainStyledAttributes(attrs, R.styleable.GridLayout); this.numRows = a.getInt(R.styleable.GridLayout_numRows, -1); Nothing comes back (-1 does but that means nothing is there) If I use int n = a.getIndexCount(); I get 0.

    Read the article

  • Best gui toolkit to use for creating 3D board game

    - by UserInteractive
    I have created a board game using Java and Swing - using GridLayout and various other apis. It works properly but the UI looks very very simple. I would want couple of animations like tilting the GridLayoutat any angle. There are pawns on boxes of the GridLayout that I want to be animated when somebody clicks on it. I'm not sure of the right GUI toolkit to use for this. Swing repaint is possible to a limit and cannot be used for a lot of animation and graphics. And I realized after creating the game that Swing is probably not a good tool to create games. Could anybody suggest a better framework to use that I can use it in Eclipse with Java? I was thinking of JavaFX or tools like Adobe Flash or Adobe Air. Any suggestions please?

    Read the article

  • Beginning with event listeners

    - by terence6
    I have a simple app, showing picture made of tiled images(named u1, u2,...,u16.jpg). Now I'd like to add some Events to it, so that I can show these images only when proper button is clicked. I've tried doing it on my own, but it's not working. Where am I doing something wrong? Original code : import java.awt.GridLayout; import javax.swing.*; import javax.swing.border.BevelBorder; public class Tiles_2 { public static void main(String[] args) { final JFrame f = new JFrame("Usmiech"); JPanel panel = new JPanel(new GridLayout(4, 4, 3, 3)); JLabel l = new JLabel(); for (int i = 1; i < 17; i++) { String path = "u"+ i+".jpg"; l = new JLabel(new ImageIcon(path)); l.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); panel.add(l); } f.setContentPane(panel); f.setSize(300, 300); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); } } New code : import java.awt.GridLayout; import javax.swing.*; import javax.swing.border.BevelBorder; import java.awt.event.*; public class Zad_8_1 implements ActionListener { public void actionPerformed(ActionEvent e) { JButton b = (JButton)(e.getSource()); String i = b.getText(); b = new JButton(new ImageIcon("u"+i+".jpg")); } public static void main(String[] args) { final JFrame f = new JFrame("Smile"); JPanel panel = new JPanel(new GridLayout(4, 4, 3, 3)); JButton l = null; for (int i = 1; i < 17; i++) { String path = "u"+ i+".jpg"; l = new JButton(""+i); l.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); l.setSize(53,53); panel.add(l); } f.setContentPane(panel); f.setSize(300, 300); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); } } This should work like this : http://img535.imageshack.us/img535/3129/lab8a.jpg

    Read the article

  • Multiple Layout Managers in Java

    - by ranzy
    Is there way to use more than 1 layout manager in Java. Right now I'm using a gridLayout to implement a chess board but beneath it I would like to put some other stuff but not in a gridLayout. Maybe a FlowLayout or some other layout. How would I go about doing this? Thanks!

    Read the article

  • SWT: problems with clicking button after using setEnabled() on Linux

    - by Laimoncijus
    Hi, I have a strange case with SWT and Button after using setEnabled() - seems if I disable and enable button at least once - I cannot properly click with mouse on it anymore... Already minify code to very basic: import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class TestButton { public TestButton() { Display display = new Display(); Shell shell = new Shell(display); GridLayout mainLayout = new GridLayout(); shell.setLayout(mainLayout); shell.setSize(100, 100); Button testButton = new Button(shell, SWT.PUSH); testButton.addSelectionListener(new TestClickListener()); testButton.setText("Click me!"); //testButton.setEnabled(false); //testButton.setEnabled(true); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } class TestClickListener implements SelectionListener { @Override public void widgetDefaultSelected(SelectionEvent e) { } @Override public void widgetSelected(SelectionEvent e) { System.out.println("Click!"); } } public static void main(String[] args) { new TestButton(); } } When I keep these 2 lines commented out - I can properly click on a button and always get "Click!" logged, but if I uncomment them - then I can't click on button properly with mouse anymore - button visually seems to be clicked, but nothing is logged... Am I doing something wrong here? Or maybe it's some kind of bug on Linux platform? Because on Mac running the same code I never experienced such problems... Thanks for any hint! P.S. Running code on Ubuntu 9.10, Gnome + Compiz, Sun Java 1.6.0.16

    Read the article

  • Java Stopping JApplet Components from Resizing based on Applet Size

    - by Doug
    Creating a JApplet I have 2 Text Fields, a button and a Text Area. private JPanel addressEntryPanel = new JPanel(new GridLayout(1,3)); private JPanel outputPanel = new JPanel(new GridLayout(1,1)); private JTextField serverTf = new JTextField(""); private JTextField pageTf = new JTextField(""); private JTextArea outputTa = new JTextArea(); private JButton connectBt = new JButton("Connect"); private JScrollPane outputSp = new JScrollPane(outputTa); public void init() { setSize(500,500); setLayout(new GridLayout(3,1)); add(addressEntryPanel); addressEntryPanel.add(serverTf); addressEntryPanel.add(pageTf); addressEntryPanel.add(connectBt); addressEntryPanel.setPreferredSize(new Dimension(50,50)); addressEntryPanel.setMaximumSize(addressEntryPanel.getPreferredSize()); addressEntryPanel.setMinimumSize(addressEntryPanel.getPreferredSize()); add(outputPanel); outputPanel.add(outputSp); outputTa.setLineWrap(true); connectBt.addActionListener(this); The problem is when debugging and putting it in a page the components / panels resize depending on the applet size. I don't want this. I want the textfields to be a certain size, and the text area to be a certain size. I've put stuff in there to set the size of them but they aren't working. How do I go about actually setting a strict size for either the components or the JPanel.

    Read the article

1 2 3 4 5  | Next Page >