14 Replies - 231 Views - Last Post: 18 November 2012 - 06:52 PM Rate Topic: -----

#1 Scyth3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 18-November 12

JScrollBars

Posted 18 November 2012 - 03:54 PM

I'm trying to use a JScrollBar, but the scroll bars don't even show up..

		input = new JTextArea();
		JScrollPane pane = new JScrollPane(
				JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
				JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

		frame.add(input);



Whats wrong?
Is This A Good Question/Topic? 0
  • +

Replies To: JScrollBars

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: JScrollBars

Posted 18 November 2012 - 03:57 PM

The JScrollPane constructor takes the content (input) and that is added to the JFrame.
Was This Post Helpful? 0
  • +
  • -

#3 Scyth3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 18-November 12

Re: JScrollBars

Posted 18 November 2012 - 04:02 PM

View PostGregBrannon, on 18 November 2012 - 03:57 PM, said:

The JScrollPane constructor takes the content (input) and that is added to the JFrame.


		input = new JTextArea();
		JScrollPane pane = new JScrollPane(input,
				JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
				JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
frame.add(pane);




Nothing shows up when I do that
Was This Post Helpful? 0
  • +
  • -

#4 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: JScrollBars

Posted 18 November 2012 - 04:08 PM

Can you show more than 3 lines of code? Something that runs?
Was This Post Helpful? 0
  • +
  • -

#5 Scyth3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 18-November 12

Re: JScrollBars

Posted 18 November 2012 - 04:14 PM

View PostGregBrannon, on 18 November 2012 - 04:08 PM, said:

Can you show more than 3 lines of code? Something that runs?


Nevermind, the frame was just cutting it off... Is there any way I could set my JScrollPane to always be the size of the JFrame?
Was This Post Helpful? 0
  • +
  • -

#6 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: JScrollBars

Posted 18 November 2012 - 04:16 PM

More than one, but you might start by correctly using an appropriate layout manager.
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: JScrollBars

Posted 18 November 2012 - 04:17 PM

JFrame by default have a BorderLayout
frame.add(scrollPane)
will put it in the CENTER region
should take all the available space
Was This Post Helpful? 0
  • +
  • -

#8 Scyth3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 18-November 12

Re: JScrollBars

Posted 18 November 2012 - 04:22 PM

Oh yeah, I had it set to null from earlier when I was doing some absolute positioning
Was This Post Helpful? 0
  • +
  • -

#9 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: JScrollBars

Posted 18 November 2012 - 04:26 PM

So you will have to setBounds() your ScrollPane
Was This Post Helpful? 0
  • +
  • -

#10 Scyth3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 18-November 12

Re: JScrollBars

Posted 18 November 2012 - 04:34 PM

View Postpbl, on 18 November 2012 - 04:26 PM, said:

So you will have to setBounds() your ScrollPane


Then if you resize it, it won't resize with the frame, even if you base the dimensions off of the frame
Was This Post Helpful? 0
  • +
  • -

#11 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: JScrollBars

Posted 18 November 2012 - 04:37 PM

Yha
by using null layout you defeat one of Java's nicest feature: auto resizing of all components

But you are the one who decided to set your JFrame.setLayout(null)
Was This Post Helpful? 0
  • +
  • -

#12 Scyth3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 18-November 12

Re: JScrollBars

Posted 18 November 2012 - 04:41 PM

View Postpbl, on 18 November 2012 - 04:37 PM, said:

Yha
by using null layout you defeat one of Java's nicest feature: auto resizing of all components

But you are the one who decided to set your JFrame.setLayout(null)


I know... Though that brings me to my next problem... JTextField size limiting... I've looked around an I havn't seen much on it... (With answers anyway) do you know how to do this? Limiting the columns does not work.
Was This Post Helpful? 0
  • +
  • -

#13 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: JScrollBars

Posted 18 November 2012 - 04:47 PM

Look at my multiple Secret Code tutorials like
http://www.dreaminco...-ceasar-cipher/

From a JTextField you can get a Document to which you can add a DocumentListener()
In the DocumentListener you can limit the number of character by fetching the actual text and replace it with a truncation a the user typed text if required
Was This Post Helpful? 0
  • +
  • -

#14 Scyth3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 18-November 12

Re: JScrollBars

Posted 18 November 2012 - 05:01 PM

View Postpbl, on 18 November 2012 - 04:47 PM, said:

Look at my multiple Secret Code tutorials like
http://www.dreaminco...-ceasar-cipher/

From a JTextField you can get a Document to which you can add a DocumentListener()
In the DocumentListener you can limit the number of character by fetching the actual text and replace it with a truncation a the user typed text if required


Example please? If its not to much to ask
Was This Post Helpful? 0
  • +
  • -

#15 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: JScrollBars

Posted 18 November 2012 - 06:52 PM

View PostScyth3, on 18 November 2012 - 08:01 PM, said:

Example please? If its not to much to ask

This is exactly what I gave you
http://www.dreaminco...-ceasar-cipher/

just change the
changedUpdate()
insertUpdate()
removeUpdate()

methods to call a common method that will
String str = jtextfield.getText();
if(str.length() > yourMax) jtextfield.setText(str.subString(yourMax));
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1