SEARCH YOUR SOLUTION HERE  

Want to know about border Layout and gridbag layout

I need help on java swing layouts.............

Please help asap.

Posted On: Wednesday 17th of October 2012 05:30:49 AM Total Views:  168
View Complete with Replies




Related Messages:

Confusion about this reference to a JFrame   (157 Views)
import java.awt.*; import javax.swing.*; public class SimpleScreenManager{ private GraphicsDevice device; SimpleScreenManager(){ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); device = ge.getDefaultScreenDevice(); } public void setFullScreen(DisplayMode displayMode, JFrame window){ window.setUndecorated(true); window.setResizable(false); device.setFullScreenWindow(window); //test if displayMode has parameters passed to it and change mode is supported if(displayMode != null && device.isDisplayChangeSupported()){ try{ device.setDisplayMode(displayMode); } catch (IllegalArgumentException ex){ //ignore illegal mode for this device } } } public Window getFullScreenWindow (){ return device.getFullScreenWindow(); } public void restoreScreen(){ Window window = device.getFullScreenWindow(); if(window!=null){ window.dispose(); } device.setFullScreenWindow(null); } } import java.awt.*; import javax.swing.*; public class FullScreenTest extends JFrame{ public static void main(String [] args){ DisplayMode displayMode; //Checking if args were passed via the command line ie java FullScreenTest 800,600,32 if(args.length == 3){ displayMode = new DisplayMode( Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]), DisplayMode.REFRESH_RATE_UNKNOWN); } //setting default display settings if no args were used else { displayMode = new DisplayMode(800,600,32, DisplayMode.REFRESH_RATE_UNKNOWN); } FullScreenTest test = new FullScreenTest(); test.run(displayMode); } private static final long Demo_Time = 5000; public void run(DisplayMode displayMode){ setBackground(Color.blue); setForeground(Color.white); setFont(new Font("Dialog", Font.PLAIN, 24)); SimpleScreenManager screen = new SimpleScreenManager(); try { screen.setFullScreen(displayMode, this); try { Thread.sleep(Demo_Time); } catch (InterruptedException ex){} } finally { screen.restoreScreen(); } } public void paint(Graphics g){ g.drawString(" World",20,50); } }
Swing not Showing Windows like button and borders   (191 Views)
These buttons are not like Windows 7 buttons. i m using JFrame. how can i make that type of buttons like gray buttons with gray hover etc(windows style).
Question about drop down lists from JComboBox within an applet   (189 Views)
When I click on the down arrow of a standard JComboBox in an applet and the list of strings are displayed, if I then drag the browser window, the drop down list stays in the same place instead of either being closed or moving with the browser window. I started noticing this when I started using Java 7, but I think this also occurs with Java 6 and 5. When run within the applet viewer in Eclipse, moving the applet window there closes the drop-down during the process of moving the window. Anybody else noticing this If so are any suggestions for a possible solution. Ideally I'd want the list to move with the browser window without the drop-down closing. My example code that demonstrates the problem is as follows: import javax.swing.JApplet; import javax.swing.JComboBox; public class ComboApplet extends JApplet { public void init () { String [] testStrings = new String [] {"This", "is", "a", "test"}; JComboBox comboBox = new JComboBox(testStrings); add(comboBox); } }
How to make a JFrame transparent with solid border   (217 Views)
Hi , I am wondering how to make the content pane of a JFrame transparent, but not its border. The border is still opaque and solid. Does anyone have ideas
Question about programming style   (193 Views)
When creating a gui application or an applet, is there a standard about the best way to set up the code For example, is it better to layout the code like this public void init() { setLayout(null); output = new JTextField("This is a textfield", 100); output.setBounds(0, 0, 100, 50); add(output); one = new JButton("1"); one.setBounds(5, 40, 50, 50); add(one); two = new JButton("2"); two.setBounds(65, 40, 50, 50); add(two); }
Changing a border size   (54 Views)
I have an object that I want to be be a perfect square no matter how large the window gets, but I don't want it to be restricted to a certain size (aka, as big as it can get within the window). The problem is, I have an empty border for padding around it that I want to also adjust in proportion with the size. The problem is, every time I use setBorder() in the paint method (where I've been putting all my re-size code), it doesn't work. I think it's creating an infinite loop but I'm not sure. Anyone know what the problem is and how I can fix this
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.swing.border.BevelBo   (106 Views)
Hi all am getting this exceptional error Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.swing.border.BevelBorder.(BevelBorder.java:78) at javax.swing.border.SoftBevelBorder.(SoftBevelBorder.java:71) at Pack1.WlcmScr.initComponents(WlcmScr.java:54) at Pack1.WlcmScr.(WlcmScr.java:17) at Pack1.WlcmScr$1.run(WlcmScr.java:192) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705) at java.awt.EventQueue.access$000(EventQueue.java:101) at java.awt.EventQueue$3.run(EventQueue.java:666) at java.awt.EventQueue$3.run(EventQueue.java:664) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:675) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) at java.awt.EventDispatchThread.run(EventDispatchThread.java:90) and my code goes like this package Pack1; public class WlcmScr extends javax.swing.JFrame { public WlcmScr() { initComponents(); } private void initComponents() { jLabel1 = new javax.swing.JLabel(); jPanel1 = new javax.swing.JPanel(); jLabel4 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jScrollPane2 = new javax.swing.JScrollPane(); jTextPane2 = new javax.swing.JTextPane(); jButton1 = new javax.swing.JButton(); jPasswordField2 = new javax.swing.JPasswordField(); jButton2 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Captain's Security Services"); setBackground(new java.awt.Color(153, 153, 255)); setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); setMaximizedBounds(new java.awt.Rectangle(0, 0, 0, 0)); setPreferredSize(new java.awt.Dimension(1024, 768)); setResizable(false); jLabel1.setBackground(new java.awt.Color(153, 153, 255)); jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 36)); // NOI18N jLabel1.setText("Captain's Security Services"); jLabel1.setAlignmentY(0.0F); jPanel1.setBackground(new java.awt.Color(0, 0, 102)); jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.white, null)); jPanel1.setForeground(new java.awt.Color(255, 255, 255)); jLabel4.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N jLabel4.setForeground(new java.awt.Color(255, 255, 255)); jLabel4.setText("Password :"); jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N jLabel3.setForeground(new java.awt.Color(255, 255, 255)); jLabel3.setText("User Name :"); jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N jLabel2.setForeground(new java.awt.Color(255, 255, 255)); jLabel2.setText("Login"); jScrollPane2.setViewportView(jTextPane2); jButton1.setText("Login"); jButton1.setToolTipText(""); jButton2.setText("Cancel"); jButton2.setActionCommand("Exit"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addContainerGap(72, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(131, 131, 131) .addComponent(jLabel2)) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3) .addComponent(jLabel4) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(37, 37, 37) .addComponent(jButton1))) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(84, 84, 84) .addComponent(jButton2) .addGap(91, 91, 91)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jScrollPane2) .addComponent(jPasswordField2, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)))))) .addGap(63, 63, 63)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(37, 37, 37) .addComponent(jLabel2) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(42, 42, 42) .addComponent(jLabel3)) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(40, 40, 40) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(jPasswordField2, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(53, 53, 53) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) .addComponent(jButton2)) .addGap(26, 26, 26)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(233, 233, 233) .addComponent(jLabel1)) .addGroup(layout.createSequentialGroup() .addGap(216, 216, 216) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(253, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel1) .addGap(204, 204, 204) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(198, Short.MAX_VALUE)) ); pack(); } public static void main(String args[]) { try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(WlcmScr.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(WlcmScr.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(WlcmScr.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(WlcmScr.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new WlcmScr().setVisible(true); } }); } private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JPanel jPanel1; private javax.swing.JPasswordField jPasswordField2; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTextPane jTextPane2; }
Question about Color and BufferedImage   (140 Views)
Hi , I'm trying to learn more about java computer graphics, and in my study I encountered following problem. Probably there is a simple solution to this, but I'm baffled. Here's the question, why the integers that represent color are not the same Also I noticed that when I change value 255 => 254 the integer of the color object gets recalculated but the one in the bufferedImage doesn't, why is that public static void main(String[] args) { Color c = new Color(255, 110, 75, 100); BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); Graphics g = image.getGraphics(); g.setColor(c); g.fillRect(0, 0, 100, 100); System.out.println(c.getRGB()); System.out.println(image.getRGB(40, 40)); } Console: 1694461515 1694461514
Doubt about layouts.. (its simple I think)   (149 Views)
My doubt is simple, I dont want to use AbsoluteLayout. So, I putted a Panel inside a frame on the West position using BordeLayout (default). Then I set the frame layout to BoxLayout (YAXIS). So I putted a JLabel and a JTextBox. I wanted it: Nome: [___________________________________] But the JTextBox extended until the border of the panel. How do I fix it
Advice about Eclipse Window Builder config   (189 Views)
Hi Im creating a big project and I want to listen your opnion about the automatic event handler generation. See the screen below: ` As you can see Im using anonymous classes for event handling. Its the best way for big projects or you don't think so I really like that all the things clear and for big projects I don't know if this is the best configuration.
Question about GUI (with NetBeans IDE)   (173 Views)
. I want to ask about my vision for the GUI. I'm using NetBeans IDE to make it. My idea is something like this, we have a few JPanels with JLabels, and JButtons. First JPanel it's a menu and it is only visible JPanel at the application starts. When we click on the one of the buttons (let's say "Information") we change Menu JPanel Visibility to false, and the JPanel which include the "Information" is now Visible. The JPanel "Information" also has got JLabels and JButtons, and one of JButtons is a "Main Menu" which (when clicked) sets the Menu JPanel visibility as true, and set Information JPanel visibility as false. My second idea (which is just stupid ;>) is to remove all components on JButton click, and create new components. So in Menu JPanel we got JButton information. When we click it, we remove all components that are in Menu JPanel, and we create new components, that are needed in Information JPanel. I think that both ideas are terrible, but I have no other idea how to make it. I was thinking about web app, but I don't have such knowledge to create it.
Swing, awareness about unsaved data   (191 Views)
I am working on a Swing application for data maintenance (Java 6). There is a JFrame with several JTextFields. If the user is editing a record, there is UNSAVED data until she/he presses the Save-Button. The application should always be aware if there is unsaved data. How can this be done Best regards Gerald
Anybody can tell me some websites about investigating the Swing or other UI deeply?   (254 Views)
Can anybody tell me some websites about investigating the Swing or other UI deeply Thank you,everybody in advance.
Question about "Java Icons"   (107 Views)
I am creating an application, in this application, I need to use Icons like "copy", "paste", "cut" etc. Rather than using images of my own as Icons, I know there are some "Built In Icons' in Java. Anyway, According to my requirement, there should be at least two type of the same icon, for an example, "Copy Icon NORMAL" and "Copy icon MouseHover". Is there is any kind of FREE package which provide these Icons Apart from that, this is the first time I am gonna use these BUILT IN ICONS, so please tell me how to use these too.
Capture Click on border of JFrame   (52 Views)
I want to capture mouse clicks on the border of a JFrame. Here's Why: I have successfully disabled "Print Screen" of my window. Here's my code. class FrameTest extends JFrame { public FrameTest() { KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() { @Override public boolean dispatchKeyEvent(KeyEvent ke) { if (ke.getKeyCode() == KeyEvent.VK_PRINTSCREEN) { //do whatever i want to... return true; } return false; } }); } }
How to make the window (JPanel?) bigger in gridbaglayout   (156 Views)
When I run this program, the window pops up and everything is smooshed (for lack of a better term) together. How do I change the size of it I'm using GridBagLayout.
Absolute layout on nested panel   (70 Views)
I have a GUI in which I want absolute positioning within a subpanel. I'm using GridBagLayout elsewhere, including the parent. When I set the layout manager to null on a top level panel, everything works as I'm expecting. But, when trying to do the same on a subpanel, I get a blank panel (no visible controls). I've reduced this down to a code fragment (based on examples from the web) that can demonstrate this both ways by setting an (obviously named) boolean variable. Here's the code fragment: public static void addComponentsToContainer( JPanel panel ) { panel.setLayout( null ); JButton b1 = new JButton( "1" ); JButton b2 = new JButton( "2" ); JButton b3 = new JButton( "3" ); panel.add( b1 ); panel.add( b2 ); panel.add( b3 ); b1.setBounds( 10, 5, 60, 25 ); b2.setBounds( 30, 40, 60, 25 ); b3.setBounds( 50, 75, 60, 25 ); } public static void main( String[] args ) { JFrame frame = new JFrame(); JPanel parent = new JPanel(); JPanel panel = parent; boolean iWantItToFail = true; if ( iWantItToFail ) { JPanel child = new JPanel(); parent.add( child ); panel = child; } addComponentsToContainer( panel ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.setContentPane( parent ); frame.setSize( 150, 150 ); frame.setVisible( true ); }
problem in border layout.   (102 Views)
i add two classes with border layout to my frame, one is in center and one is in south but in the border layout "If nothing has been added to a region, the neighboring regions expand to fill that space." here also this is happening, but i want the space in the west and east also, i mean my class which is in center should not expand the neighbor space(ie. west and east), how to do this
what layouts to use   (56 Views)
i finally came up with a small project to keep me busy for a while. i am writing a "copy" of windows Calculator program(in the standard view). if you have windows and could give your ideas on how to lay it out so it looks the same it would help some. so far, ignoring the menubar, i have a border layout with the TextField taking up north, and a panel with a grid layout taking center. however, this wont work because the top row has less components than the rest of the rows. maybe if i give the panel a border layout, add a panel to it in north with a flow layout, and a panel to it in center with a grid layout